For Programmers: Free Programming Magazines  


Home > Archive > Java Help > May 2004 > Re: freeing resources allocated in a static bloc initilaisation of a class ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: freeing resources allocated in a static bloc initilaisation of a class ?
Chris Smith

2004-05-24, 10:40 am

dpr wrote:
> I hava a class in wich I initialize a resource like this:
>
> class Dummy {
> static GlobalRessourceClass myGlobalRes;
> {
> // Static bloc initialisation
> myGlobalRes = AllocRessource();
> }
> };
>
> How can I do to free the ressource when the program exists ?


First of all, are you sure you need to? It's extremely rare to find a
resource on any modern operating system that isn't automatically
reclaimed when a process exits.

If you need to do this, the safest way is generally to create an outside
watchdog process that waits for this one to end and then reclaims the
resources from the outside. Alternatively, add the logic to the normal
exit case and then add a note in the documentation about manually
cleaning up the resource if it is missed.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com