Hi Pohihihi,
if I understand correctly you are saying that if you have a collection in
form A and add an item to the same collection from form C then form C get
GCed what happens.
Basically how the GC works is that it creates a graph of relationships
from object roots, such as local variables currently in scope, items on the
stack, static objects and goes and finds all of the object that can be
reached from these roots. Objects that cannot be reached from any root are
eligable for garbage collection since there is nothing that is referencing
them. In your case, becauase you added the object in Form C to the
collection, the collection now has a reference to that object, even if FormC
goes away the garbage collector knows that the object you added still is
referenced and accessbile and it will not be collected.
I hope that answers your question.
Mark Dawson
http://www.markdawson.org
"Pohihihi" wrote:
Hello,
I have 3 form (e.g. A, B, C). Form A has collection that is passed to Form B which in turn pass that to Form C. Now this is reference rather than a copy. Now I am creating my object from my class in Form C and conditionally adding it to collection in Form A. After adding that object I dispose Form C, and user can close Form B as they want or continue with other things.
Assuming: when I add my object to the collection in Form A it is added as reference in the list of collection (as it is a big object and no copy is happening so collection will add the ref for the object in its collection list).
Question is, when I dispose Form C will the my-object that I created in Form C still exsists, and in turn some how Form C is also not disposed (GCed) as my object is part of it?
What is really happening behind?
Thanks,
Po