Re: Performance on string destruction



Setting it to null will accomplish nothing unless perhaps there is a lot of other processing in the same method before it exits. Otherwise, just let the StringBuilder reference go out of scope when the routine exits.

Deleting what's in the buffer would only make sense if you're going to reuse it. Setting the StringBuilder instance to null will cause the GC to reclaim the whole object, including the buffer, *at such time as the GC feels it's necessary*.

I emphasized the last point because so many people get bogged down in anxiously watching memory (often looking at the wrong memory indicator, as well) and then have a cow when it doesn't (appear to) be freed up. In effect, memory is marked by the GC as reclaimable when it's no longer needed.

--Bob

SevDer wrote:
Thinking for performance & system resources;

I have a string field inside a major object that contains big XML response.
When I am done with it, I want to clear out this field to give some relief to memory.


Should I use this:
    SabreContractResponse.Remove(0,SabreContractResponse.Length);
    SabreContractResponse = null;

or just this:
    SabreContractResponse = null;

or do you have any other suggestion?

Thanks
.



Relevant Pages

  • Re: out of Memory exception
    ... StringBuilder when dealing with 130mb file. ... memory for two reasons... ... I'm using a FileStream and StreamReader to read ... > size - that way it won't need to keep building up bigger buffers. ...
    (microsoft.public.dotnet.framework)
  • Re: ZoneView or ways of dealing with large objects?
    ... Are you using the StringBuilder or StringBuffer classes for your string manipulations? ... But I'd still like a more scalable solution than relying on memory manipulation. ... What happens when I try to display a file that's bigger than main memory + swap file? ... I plan on doing some heavy graphics work in the future so I'm interested in solutions for very large file sizes. ...
    (comp.lang.java.help)
  • Re: StringBuilder vs. String performance
    ... StringBuilder instead" has been due to someone complaining about speed, ... In my experience at least, I have seen more benefit in saving memory, ... Optimization is optimization, and both speed and memory should be watched at ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: XmlTextWriter Speed Increase?
    ... StringBuilder sb = new StringBuilder); ... If it still report OOM exception, that means your system memory ... And for the file based approach, if you want improve the cache size and how ... Subject: XmlTextWriter Speed Increase? ...
    (microsoft.public.dotnet.framework)
  • Re: XmlTextWriter Speed Increase?
    ... What if you reuse the buffer rather than creating a new one each time? ... StringBuilder sb = new StringBuilder); ... If it still report OOM exception, that means your system memory ... Subject: XmlTextWriter Speed Increase? ...
    (microsoft.public.dotnet.framework)