Hi All,
I raised similar question recently
http://root.cern.ch/root/roottalk/roottalk01/0225.html
I need deallocate resources ( destruct some objects )
in following cases:
1. when root application terminates
1.1 by normal exit ( by root[].q , gApplication->Terminate(0), etc )
1.2 by abnormal exit ( SIGKILL etc ...
see ESignals from http://root.cern.ch/root/htmldoc/TSysEvtHandler.h )
2. when user does gROOT->Reset()
3. when shared library in which these objects defined is unloaded
( by root[].U myLib.so, gSystem->Unload(myLib), etc. )
Solutions:
- For 1.1 => use gSystem->RemoveOnExit(objectToBeDeleted)
- For 1.2 => use
TSignalHandler* sigh = new TSignalHanler(kSigQuit);
// btw ESignals enums are not in global context yet (??)
gSystem->AddSignalHandler(sigh)
... use signal-slot com.mechanism (available in ROOT 3.0)
to add handler function for kSigXXX
- For 2. => use gROOT->GetListOfGlobals()->Add(objectTobeDeleted)
- For 3. =>
I found only exotic solution:
1. Start "thread" (aka TTimer) which periodically checks
the list of libraries curently loaded
( returned by gInterpreter->GetSharedLibs() )
2. When myLib.so is dissapeared from this list =>
remove/deallocate resources
I think good solution for 3. would be to use signal-slots
as similar as in 1.2
Regards. Valeriy
Fons Rademakers wrote:
>
> Hi Anton,
>
> this has nothing to do with ROOT but is a standard C++ feature.
> If you create an object on the heap (with new) you have to explicitely
> call delete somewhere down the line before the program exits.
> If you create the object on the stack the destructor will automatically be
> called as soon as the object goes out of scope (in case of .q). If that
> is not the case for you send me an example so we can investigate.
>
> Cheers, Fons.
>
> On Fri, Jan 26, 2001 at 11:54:33PM +0100, Anton Fokin wrote:
> > Hi,
> >
> > I noticed that ROOT doesn't call destructors for objects in memory when you
> > quit it (by .q). Is it a kind of feature? I have for example Save() function
> > in my TDataManager and since ROOT doesn't call data manager object
> > destructor the data are not saved too. Of course I can add things in
> > rootlogoff.C macro but ...
> >
> > By the way, can some function (which will call destructors, close open
> > files, sockets, etc.) be called on the system (root session) crash?
> >
> > Regards,
> > Anton
>
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:34 MET