J
Joanna Carter \(TeamB\)
Following on from the other discussion, I have to just check something out
with reference to disposal of resources held in static fields.
I have a Persistence Framework that is 'globally accessible'. In Delphi, I
would use a class of static methods to enforce the singleton, and I added
static fields to hold things like the database connections, etc.
This worked fine in Delphi because we have unit initialisation/finalisation
sections that can act as static constructors/destructors, and with
deterministic finalisation, we could simulate a static destructor in the
finalisation and clean up resources there on application closedown.
Now, bearing in mind that if I use the 'proper' Singleton pattern, I am
always accessing a static field through a static method, I can't see any
difference between using my own class of static methods to access the static
fields, and using the Singleton pattern.
My question is, do the instances pointed to by static fields ever get
garbage collected ?
I have always assumed that this happened as part of the tidy-up code that
got executed when the application quit.
Joanna
with reference to disposal of resources held in static fields.
I have a Persistence Framework that is 'globally accessible'. In Delphi, I
would use a class of static methods to enforce the singleton, and I added
static fields to hold things like the database connections, etc.
This worked fine in Delphi because we have unit initialisation/finalisation
sections that can act as static constructors/destructors, and with
deterministic finalisation, we could simulate a static destructor in the
finalisation and clean up resources there on application closedown.
Now, bearing in mind that if I use the 'proper' Singleton pattern, I am
always accessing a static field through a static method, I can't see any
difference between using my own class of static methods to access the static
fields, and using the Singleton pattern.
My question is, do the instances pointed to by static fields ever get
garbage collected ?
I have always assumed that this happened as part of the tidy-up code that
got executed when the application quit.
Joanna