By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

ICloneable and releasing memory

P: n/a
ib
ICloneable::Clone returns a new instance of the object being cloned.
However, it seems possible that the garbage collector could release this
memory before the calling function receives a reference to the memory. If
this can occur then it introduces an error that would only occur at random
times. Is this really a problem or does .NET take the necessary steps to
ensure the memory is first referenced by the calling function before the
garbage collector gets a chance to check the memory?

Thanks,

Ian
Dec 5 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Ian,

I don't see why returning a new object from a method named, "Clone" would be
any different, in terms of GC, from returning a new object from any other
method. What exactly is your concern here?

--
Dave Sexton

"ib" <ib@yahoo.comwrote in message
news:NY**********************@wagner.videotron.net ...
ICloneable::Clone returns a new instance of the object being cloned.
However, it seems possible that the garbage collector could release this
memory before the calling function receives a reference to the memory.
If this can occur then it introduces an error that would only occur at
random times. Is this really a problem or does .NET take the necessary
steps to ensure the memory is first referenced by the calling function
before the garbage collector gets a chance to check the memory?

Thanks,

Ian

Dec 5 '06 #2

P: n/a

ib wrote:
ICloneable::Clone returns a new instance of the object being cloned.
However, it seems possible that the garbage collector could release this
memory before the calling function receives a reference to the memory. If
this can occur then it introduces an error that would only occur at random
times. Is this really a problem or does .NET take the necessary steps to
ensure the memory is first referenced by the calling function before the
garbage collector gets a chance to check the memory?
Why would the memory have to be referenced "by the calling function"?

There is a reference to the memory on the stack, either as a local
variable in the Clone method, as a return value from the Clone method,
or as a local variable in the calling method. Since the GC walks the
stack as one of its ways of determining what is currently in use, it
will find a reference to the memory throughout the cloning process.

It's no different from new-ing an object and returning it from any
other method.

Dec 5 '06 #3

P: n/a
ib
Please disregard this posting. I have posted it else where.

Thanks,

Ian
Dec 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.