473,473 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

big confusion

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
Jan 13 '06 #1
7 1389
I may get this wrong but in "smart pointer" terms then what would
happen is you have an object A and each time you make a copy of it
(reference) the the count is incrememented. The object is not clear
for collection until that count reaches 0.

There are cases of circular relationships and relationships involving
events that can arise. These are a bit too complex for me to explain
without reviewing them but it is possible to have the dead listeners.

However, when you refer to "created in form C" then you need to look at
the scope that the object lives in. If that object is still valid then
yes it will still be alive or else it wont. But will form C be valid
then only if there is an object that is in scope.

I think you are confusing the class data and object data. I think the
answer is no to your question but not sure I fully understood it.
Curtis
http://www.ghostclip.com
Premier Popup Notepad & Help System For Developers

Jan 13 '06 #2
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

Jan 13 '06 #3
>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?
Form C and my-object are allocated separately on the managed-heap. The
fact that Form C holds a reference to my-object does not make it to be
collected when Form C is collected. my-object memory location is still
referenced by the collection which in turn referenced by Form A so it
is not eligible for being collected.

Jan 13 '06 #4
If I understand even Form C is collected my-object will be alive. What part
is not clear is that will Form C go away or will hang around until my-object
is alive. As per Truong's reply what I get is that object will still be
alive and Form C will be collected. If that is so then I get the answer
correctly. Thanks,
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
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

Jan 13 '06 #5
Yes, that is it. Whenever an object is created with the "new" operator,
it is allocated on the managed heap. It does not matter which
class/method creates it. When the object becomes unreachable (no
references to it from alive objects), it is eligible for garbage
collection. The fact that my-object is created in one of the Form C's
methods does not make any sense to the GC.

Thi

Jan 13 '06 #6
Thanks,
"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Yes, that is it. Whenever an object is created with the "new" operator,
it is allocated on the managed heap. It does not matter which
class/method creates it. When the object becomes unreachable (no
references to it from alive objects), it is eligible for garbage
collection. The fact that my-object is created in one of the Form C's
methods does not make any sense to the GC.

Thi

Jan 13 '06 #7
Truong Hong Thi wrote:
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?
Form C and my-object are allocated separately on the managed-heap. The
fact that Form C holds a reference to my-object does not make it to be
collected when Form C is collected. my-object memory location is still
referenced by the collection which in turn referenced by Form A so it
is not eligible for being collected.


It's very hard to follow exactly what you're talking about without
concrete code. Could you provide a short but complete code example of
what's happening and state what you *want* to happen?

Jon

Jan 13 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JMCN | last post by:
object invalid or no longer set - confusion of the recordset in access 2003. i am currently converting from access 97 to access 2003. majority of the codes converted over perfectly fine, though...
0
by: i_have_control | last post by:
I'd be grateful for any input on this one: I have three web domains. The destinations of two are set to folders on the first, though that fact is transparent to the user (i.e: it does not...
13
by: Steve | last post by:
I have a form with a dataset and a datagrid. I created a dataview on this dataset. When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique. Here is...
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
1
by: Richard Lewis Haggard | last post by:
I'm having a problem with what appears to be some sort of confusion with references. I have a single solution with a dozen projects which has been working quite nicely for a while. The references...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.