Reading Object with TF1 data member and GarbageCollection

To whom it ma concern,

Hello!

I have written a class that I would like to save to a file and then read back from a file.
I have done this with other objects but this one has a TF1 pointer data member.
The crash occurs only when it is streamed , i.e., the following does not work:

class someclass : public TNamed {
...
public:
   TF1 * fFunction; //->
...

While this of course does work :

class someclass : public TNamed {
...
public:
   TF1 * fFunction; //!
...

After banging around for a while I had found a work around to quit without the crash.
[ul]
[li]Creating and a saving the object to disk works fine. [/li]
[li]Opening the file and printing the object works fine. Everything seems good. [/li]
[li]Then quiting after reading the object causes a crash (see below).[/li]
[li]If just before I quit, I call TCollection::StartGarbageCollection(), then quit, every thing works fine. [/li][/ul]
What is happening when I call TCollection::StartGarbageCollection() that fixes the quit problem?

After reading the object I quit root with a “.q” and I get the following:

[code]===========================================================
There was a crash (#7 0xb797ec1d in SigHandler () from /usr/local/root-5.32.00/lib/libCore.so).
This is the entire stack trace of all threads:

#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb6f1a6b3 in waitpid () from /lib/tls/i686/cmov/libc.so.6
#2 0xb6ebfb8b in ?? () from /lib/tls/i686/cmov/libc.so.6
#3 0xb6fdf5dd in system () from /lib/tls/i686/cmov/libpthread.so.0
#4 0xb797a44d in TUnixSystem::Exec ()
from /usr/local/root-5.32.00/lib/libCore.so
#5 0xb798239e in TUnixSystem::StackTrace ()
from /usr/local/root-5.32.00/lib/libCore.so
#6 0xb797eb4b in TUnixSystem::DispatchSignals ()
from /usr/local/root-5.32.00/lib/libCore.so
#7 0xb797ec1d in SigHandler () from /usr/local/root-5.32.00/lib/libCore.so
#8 0xb7977794 in sighandler () from /usr/local/root-5.32.00/lib/libCore.so
#9
#10 0x0848ef23 in ?? ()
#11 0x00000011 in ?? ()
#12 0xb791a9aa in TCollection::GarbageCollect ()
from /usr/local/root-5.32.00/lib/libCore.so
#13 0xb7921738 in TList::Delete () from /usr/local/root-5.32.00/lib/libCore.so
#14 0xb78c62e0 in TROOT::~TROOT () from /usr/local/root-5.32.00/lib/libCore.so
#15 0xb78c6500 in __tcf_0 () from /usr/local/root-5.32.00/lib/libCore.so
#16 0xb6eb58c1 in __cxa_finalize () from /lib/tls/i686/cmov/libc.so.6
#17 0xb7871b13 in __do_global_dtors_aux ()
from /usr/local/root-5.32.00/lib/libCore.so
#18 0xb7d2578c in _fini () from /usr/local/root-5.32.00/lib/libCore.so
#19 0xb7f22a1f in ?? () from /lib/ld-linux.so.2
#20 0xb7f30260 in _rtld_global () from /lib/ld-linux.so.2
#21 0x00000000 in ?? ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#10 0x0848ef23 in ?? ()
#11 0x00000011 in ?? ()
#12 0xb791a9aa in TCollection::GarbageCollect ()
from /usr/local/root-5.32.00/lib/libCore.so
#13 0xb7921738 in TList::Delete () from /usr/local/root-5.32.00/lib/libCore.so
#14 0xb78c62e0 in TROOT::~TROOT () from /usr/local/root-5.32.00/lib/libCore.so
#15 0xb78c6500 in __tcf_0 () from /usr/local/root-5.32.00/lib/libCore.so
#16 0xb6eb58c1 in __cxa_finalize () from /lib/tls/i686/cmov/libc.so.6
#17 0xb7871b13 in __do_global_dtors_aux ()
from /usr/local/root-5.32.00/lib/libCore.so
#18 0xb7d2578c in _fini () from /usr/local/root-5.32.00/lib/libCore.so
#19 0xb7f22a1f in ?? () from /lib/ld-linux.so.2
#20 0xb7f30260 in _rtld_global () from /lib/ld-linux.so.2
#21 0x00000000 in ?? ()

pure virtual method called
terminate called without an active exception
[/code]

The last two lines are weird to me because I don’t even inherit an ABC… anyway…

Perhaps this is a bug in the auto streamer generation, or did I mess up somewhere?

Cheers,
Whitney

A quick follow up…
If I put the function in a TList it works fine.
But a single Pointer to a TF1 will not work.

Cheers,
Whitney

[quote]Then quiting after reading the object causes a crash (see below).
[/quote]The TF1 is recorded both in your object and in the list of functions. During process exit some of the feature are turned off. For example I can see your problem happening if your class is deleted (and delete the TF1) only after then tear down has started.

To pin-point exactly the problem, you can try running your example with valgrind.

Likely the solution is to delete your object (and/or the TFile) earlier in your process.

Cheers,
Philippe.