R
Rolf Welskes
Hello,
I have the following fundamental problem.
Say I have a class ClsA and a class ClsB
When the system works many objects of ClsB are generated, used and then
freed.
Now I have from any object clsB01 for example to inform all other existing
objects clsB02, clsB03 etc.
For this I have a collection of ClsB objects in ClsA.
Furthermore each ClsB objekt has a back-Referenz to ClsA.
so I have the following:
clsA <-> clsB01
<-> clsB02
<-> clsB03, ....
So for example clsB02 can inform over clsA all other means clsB01, clsB03.
In reality this are many objekts.
Now, this ClsB-Objekts are used anywhere in the program and then they are
never longer used and are free.
If they are not yet used, they must not be informed,
means if I have clsB02, but clsB01 for example is no longer used it must not
be informed.
Since again and again new ClsB objects are generated used and then are again
free,
they would never be garbace collected, because I allways had a reference to
this objects in the Collection of ClsA.
I have thought the following solution:
I do not lay ClsB objects in the collection of ClsA, but WeakReferences to
ClsB.
So if a ClsB object is no longer used any time later the GC would free the
object.
From time to time I check the Collection in ClsA and if a WeakReference
IsAlive is false, I delete it.
So I can inform from any ClsB object another, if it exists and on the other
hand
the Collection would be as small as possible.
Ok.
Now the question.
All this only works, if the fact, that I have a WeakReference on an object
does not influence the garbage collector
when to remove the object the Weakrefence points to.
Means garbage collection of the ClsB objects must run as usally so, as if
there where no WeakReferences on it.
This because if the GC would say there is a weakReference on the object I
clean the object only if there is memory needed,
this could mean, that such an application could have hundrets of megabyte
memory for not used ClsB objects.
this problem is a fundamental design problem and a little complex.
Thank you for any help, realy thank you to any who can help in this case.
Best Regards
Rolf Welskes
I have the following fundamental problem.
Say I have a class ClsA and a class ClsB
When the system works many objects of ClsB are generated, used and then
freed.
Now I have from any object clsB01 for example to inform all other existing
objects clsB02, clsB03 etc.
For this I have a collection of ClsB objects in ClsA.
Furthermore each ClsB objekt has a back-Referenz to ClsA.
so I have the following:
clsA <-> clsB01
<-> clsB02
<-> clsB03, ....
So for example clsB02 can inform over clsA all other means clsB01, clsB03.
In reality this are many objekts.
Now, this ClsB-Objekts are used anywhere in the program and then they are
never longer used and are free.
If they are not yet used, they must not be informed,
means if I have clsB02, but clsB01 for example is no longer used it must not
be informed.
Since again and again new ClsB objects are generated used and then are again
free,
they would never be garbace collected, because I allways had a reference to
this objects in the Collection of ClsA.
I have thought the following solution:
I do not lay ClsB objects in the collection of ClsA, but WeakReferences to
ClsB.
So if a ClsB object is no longer used any time later the GC would free the
object.
From time to time I check the Collection in ClsA and if a WeakReference
IsAlive is false, I delete it.
So I can inform from any ClsB object another, if it exists and on the other
hand
the Collection would be as small as possible.
Ok.
Now the question.
All this only works, if the fact, that I have a WeakReference on an object
does not influence the garbage collector
when to remove the object the Weakrefence points to.
Means garbage collection of the ClsB objects must run as usally so, as if
there where no WeakReferences on it.
This because if the GC would say there is a weakReference on the object I
clean the object only if there is memory needed,
this could mean, that such an application could have hundrets of megabyte
memory for not used ClsB objects.
this problem is a fundamental design problem and a little complex.
Thank you for any help, realy thank you to any who can help in this case.
Best Regards
Rolf Welskes