Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Garbage collector is not taking care of my unnecessary resources

                               ClassParent
                        Has a shared Field(DataSet)
                                   |
                                   |
   --------------------------------------------------------------------------
   |                  |                   |                       |
   #                  #                   #          ~~~~~~~~~~   #
 ClassChild1         ClassChild2         ClassChild3             ClassChild'N'

The above diagram states the picture of my current case. The ClassChild1 ... N are the forms that i am working on. That forms are actually utilizing that shared dataset during the runtime. But i just realised that when ever i am closing all the opened forms one by one, That shared field not getting disposed even after i closes all the forms.

I wonder that this is a natural behavior or something abnormal. If it is abnormal then, can anybody tell me the exact way to handle this properly.?

Upvotes: 0

Views: 95

Answers (1)

Carlos Landeras
Carlos Landeras

Reputation: 11063

Shared objects won't be collected since they are accessible for the full lifetime of the application. This is one of the main concerns of using shared variables. They are always wasting/using memory.

It you set a shared variable to null, it will not be referenced anymore and It will be collected by GC

Upvotes: 1

Related Questions