Originally posted by Sarath Chandra:
So making bstream and other objects in the Clone method as null reference will make these objects to be garbage collected freequently?
No, I didn't say a
word of anything like that, did I?
There is only one situation in which deliberately setting local variables to null does any good at all: if the method performs multiple steps, runs for a long time, and the data used by the first step is not used during the second step. Even so, this only matters
while the method is running. As soon a any method returns, it's exactly as if you had set all its local variables to null.
I've discussed at least three different ways to improve the performance of this program significantly, and none of them has anything to do with setting local variables to null. Regardless of what you've read or been told, setting local variables to null is
very rarely the answer to everything. Instead of concentrating on this, and on what the memory profiler is telling you, rather you should think about the suggestions made above.
For example, if you think there are two many String instances, this could be because the deep clone() is copying all the Strings that are part of your object and its members. Replacing that clone() with a shallow(er) one that didn't copy the strings would not only be faster, but would significantly reduce the number of Strings being created in the first place!