Hi there,
hope then someone can explain the following behaviour to me:
in best Connor MacLeod - manner, I have a object which simly tries to live forever. And I really want it to die ;-)
This is the situation:
I have a class named "Data". It has a couple of private static references, one of which is a object called "DataFile" (Yes, it's the B&S assignment ;-). In the constructor of Data I'm checking whether _DataFile is still a null reference. If so, I creating a instance of DataFile and assign it. If not, I skip this part. The reason of this is that DataFile encapsulates some file i/o stuff for reading and writing to a single data file.
I also have a static counter, which I increment each time the constructor is called. As a primitive int, it's initialized with zero.
This is the behaviour:
I have a testsuite (
jUnit). In the setUp() method, I create a Data object.
From the logging I see the instance count being 1 after the constructor finished.
In any
test method textXy() (way behind the scope setUp()), I create new Data objects
From the logging I see the instance count being 2,3,4,... after the constructors finished!!!
I added a method shutDown() to Data, explicitely nulling all class members. Even the static Logger. Called it at the end of each scope. Same result like above.
I have two questions:
- why does this happen?
- how can I ensure my Data objects to be dead and gone?
Thanks and greetings from cold Berlin,
Jan.