# Slow objects destruction

**URL:** <https://root-forum.cern.ch/t/slow-objects-destruction/9959>\
**Category:** TMVA\
**Created:** [April 14, 2010, 12:34pm UTC](https://root-forum.cern.ch/t/slow-objects-destruction/9959 "2010-04-14T12:34:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zvyagin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/cc9497/32.png) [@zvyagin](https://root-forum.cern.ch/u/zvyagin)\
**Post date:** [April 14, 2010, 12:34pm UTC](https://root-forum.cern.ch/t/slow-objects-destruction/9959/1 "2010-04-14T12:34:06Z")

</div>

In my code I produce quite a lot of Roo\* objects. Their creation time is fast. But when the program is about to finish and I start to release memory (delete object), I see that the destruction time is verrrry slow: it is about 10 objects per second. I use MacOS and I “sampled” the process at the moment when the objects were being deleted. Pleadee have a look to the log below. There are pretty many calls for “Find”,“Cache” which (I think) are slow. Is it a bug or feature? I know the objects which I need to remove. I definitely can do this orders of magnitude faster with a direct “delete” calls. How can I speed up the code?

“C programmers think memory management is too important to be left to the computer. Lisp programmers think memory management is too important to be left to the user.  
(from Ellis and Stroustrup’s The Annotated C++ Reference Manual)”

Thanks,  
Alexander.

[codeTotal number in stack (recursive counted multiple, when \>=5):  
47 operator delete(void\*)  
46 free  
43 szone\_free\_definite\_size  
25 THashList::RecursiveRemove(TObject\*)  
25 operator delete  
16 TStorage::ObjectDealloc(void\*)  
15 TObject::operator delete(void\*)  
14 TList::Remove(TObject\*)  
13 TList::FindLink(TObject const\*, int&) const  
13 TList::RecursiveRemove(TObject\*)  
13 TObject::~TObject()  
12 TDirectory::RecursiveRemove(TObject\*)  
11 RooNameSet::~RooNameSet()  
11 RooNormSetCache::~RooNormSetCache()  
11 TListIter::Next()  
11 small\_free\_list\_add\_ptr  
10 RooCacheManager::~RooCacheManager()  
10 RooObjCacheManager::~RooObjCacheManager()  
9 RooAbsArg::~RooAbsArg()  
9 RooAbsReal::~RooAbsReal()  
9 RooLinkedList::Remove(TObject\*)  
9 RooRealVar::~RooRealVar()  
8 RooAbsPdf::~RooAbsPdf()  
8 TString::~TString()  
7 RooLinkedList::findLink(TObject const\*) const  
6 RooAbsCollection::~RooAbsCollection()  
6 TObject::IsEqual(TObject const\*) const  
5 RooAbsCollection::safeDeleteList()  
5 RooAbsRealLValue::~RooAbsRealLValue()  
5 RooLinkedList::Delete(char const\*)  
5 szone\_size

Sort by top of stack, same collapsed (when \>= 5):  
szone\_free\_definite\_size 889  
small\_free\_list\_add\_ptr 233  
RooLinkedList::findLink(TObject const\*) const 196  
RooHashTable::~RooHashTable() 190  
RooAbsCollection::remove(RooAbsArg const&, bool, bool) 126  
TFormula::ClearFormula(char const\*) 110  
FitFunction::~FitFunction() 109  
RooAbsPdf::CacheElem::~CacheElem() 108  
RooPlot::~RooPlot() 100  
RooCacheManager\<std::vector\<double, std::allocator \> \>::~RooCacheManager() 96  
TList::FindLink(TObject const\*, int&) const 84  
szone\_size 48  
RooCacheManager::~RooCacheManager() 31  
TListIter::Next() 31  
std::\_Deque\_iterator\<RooAbsCache\*, RooAbsCache\*&, RooAbsCache\*\*\> std::\_\_find\<std::\_Deque\_iterator\<RooAbsCache\*, RooAbsCache\*&, RooAbsCache\*\*\>, RooAbsCache\*\>(std::\_Deque\_iterator\<RooAbsCache\*, RooAbsCache\*&, RooAbsCache\*\*\>, std::\_Deque\_iterator\<RooAbsCache\*, RooAbsCache\*&, RooAbsCache\*\*\>, RooAbsCache\* const&, std::random\_access\_iterator\_tag) 26  
THashList::RecursiveRemove(TObject\*) 25  
RooLinkedList::Delete(char const\*) 14  
Figure::~Figure() 11  
TObject::IsEqual(TObject const\*) const 9  
THashTable::RemoveSlow(TObject\*) 7  
TObject::RecursiveRemove(TObject\*) 6  
RooNormSetCache::~RooNormSetCache() 5  
posix\_madvise 5  
[/code]

---

<div class="post-metadata">

**Author:** ![joa](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@joa](https://root-forum.cern.ch/u/joa)\
**Post date:** [April 17, 2010, 5:42pm UTC](https://root-forum.cern.ch/t/slow-objects-destruction/9959/2 "2010-04-17T17:42:30Z")

</div>

Hi,

when trying do delete some 1000 TGraphs and TGraphErrors I also have  
the problem that it is VERY slow. I’ve tried to reproduce this in an script  
where I create and delete a lot of graphs, but failed… So the problem should  
be in the code I’ve written. The problem is, that when looking with “Shark”,  
profiling tool in Mac OS X, what I see is only “root”, see the included  
screen shot.

Any ideas anyone?

root-config --version --features

5.25/01 asimage astiff bonjour builtin\_afterimage builtin\_ftgl builtin\_freetype builtin\_glew builtin\_pcre builtin\_zlib cint5 cintex editline exceptions fftw3 genvector ldap mathmore memstat minuit2 odbc opengl python reflex shared ssl tmva xft xml xrootd thread

uname -a  
Darwin A-MacBook-Pro.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE\_I386 i386

that is a Macbook PRO running 10.6.3

root comiled x86\_64

cheers

Joa

---

<div class="post-metadata">

**Author:** ![joa](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@joa](https://root-forum.cern.ch/u/joa)\
**Post date:** [April 17, 2010, 6:38pm UTC](https://root-forum.cern.ch/t/slow-objects-destruction/9959/3 "2010-04-17T18:38:21Z")

</div>

…the attachment

😊

 ![](https://root-forum.cern.ch/uploads/default/original/2X/a/ad485fb2cd830f69a5999fc4fe8790150dbb49f1.png)

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [April 19, 2010, 6:34pm UTC](https://root-forum.cern.ch/t/slow-objects-destruction/9959/4 "2010-04-19T18:34:33Z")

</div>

Hi,

> [@zvyagin](#):
>
> There are pretty many calls for “Find”,“Cache” which (I think) are slow. Is it a bug or feature?

If it is what I think it is: feature in the sense that the interpreter and the rest of the C++ code communicate when objects go away, so as not to leave dangling pointers in the interpreter. This is for all TObject derived.

If you are sure you don’t need this feature, you can unset the kMustCleanup bit, which will prevent calling of the RecursiveRemove machinery.

Cheers,  
Wim

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [April 22, 2010, 7:07pm UTC](https://root-forum.cern.ch/t/slow-objects-destruction/9959/5 "2010-04-22T19:07:05Z")

</div>

Hi,

calling TH1::AddDirectory(kFALSE) before the creation of the histograms might also help.

Cheers, Axel.
