Hi Tom --
The thing about finalization is that you can never be sure when or if it
will happen. It is a bad thing to depend on.
Perhaps you could keep a list of weak references to the objects that you
create, and then after explicitly calling System.gc() you can traverse
the list and make sure that all the weak references now reference a null
entity.
-Scott
On Mon, 2006-11-06 at 13:50, Tom Ware wrote:
> Hi all,
>
> I have fixed a bug related to a memory leak and am trying to add some
> automated testing. My initial test makes use of the test case provided
> in the bug to count instances that are instantiated and reduce the count
> as the instances are finalized. When the test case is done, I invoke
> the garbage collector and give it some time to complete.
>
> The above test seems to work in a simple case, but as I add complexity
> to my test environment, the garbage collector does not reliably clean up
> the instances in the time I have allocated (or even if I increase the
> time by an order of magnitude - but does eventually clean up)
>
> Can anyone suggest a better way to test to ensure finalization occurs
> properly in an environment where the test environment is consistently
> changing and it is not predetermined what VM the tests will run on.
>
> -Tom