When is a MemoryStream released in WCF returned?

In the following scenario, I want to return only a string, because this is what the specification says, but for this I need to return a stream, and I just want to make sure that there are not too many threads for too long, The method looks like this:

[WebGet(BodyStyle = WebMessageBodyStyle.Bare,
    RequestFormat = WebMessageFormat.Xml,
    ResponseFormat = WebMessageFormat.Xml,
    UriTemplate = "someuri/{parameter}")]
[OperationContract]
public Stream FooBar(string parameter)
{
    byte[] bytes = Encoding.UTF8.GetBytes("some string");
    return new MemoryStream(bytes);
}

Does anyone know when this resource will be released?

+3
source share
2 answers

I would think of GC, as for a regular object: when all the links to it are gone.

And that's not bad, MemoryStream does implement IDisposable, but really doesn't need it.

+1
source

I did some research and found some interesting articles on the topic:

, !

+4

Source: https://habr.com/ru/post/1728153/


All Articles