# Memory/other limiting factor

**URL:** <https://root-forum.cern.ch/t/memory-other-limiting-factor/38254>\
**Category:** Newbie\
**Created:** [March 4, 2020, 12:58pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254 "2020-03-04T12:58:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinlinxc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kevinlinxc/32/21030_2.png) [@kevinlinxc](https://root-forum.cern.ch/u/kevinlinxc)\
**Post date:** [March 4, 2020, 12:58pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/1 "2020-03-04T12:58:10Z")

</div>

My program finds 72 .root files and is supposed to operate on all of them. However, it suddenly stops, usually around the 21st file. I thought maybe there was a limit to how much could be printed to the terminal, but after removing the histogram::fit output, it still got cut short. There is no error message or stack trace, it just suddenly stops and quits root:  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/9/2/92f40f90bfda842a4e703c299449776350c3366e.png)  
Could this be a problem with memory?

_ROOT Version:_ 6.18/04  
_Platform:_ Windows  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 4, 2020, 1:10pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/2 "2020-03-04T13:10:56Z")

</div>

It can be some variables allocated on the stack, which is limited. It’s better to allocate them on the heap.

---

<div class="post-metadata">

**Author:** ![kevinlinxc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kevinlinxc/32/21030_2.png) [@kevinlinxc](https://root-forum.cern.ch/u/kevinlinxc)\
**Post date:** [March 4, 2020, 1:18pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/3 "2020-03-04T13:18:17Z")

</div>

How can I do that? I looked it up and it seems I should use \* pointers instead of variables, but it seems like most of my stuff is already declared as pointers

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 4, 2020, 1:21pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/4 "2020-03-04T13:21:54Z")

</div>

Then try to start your program from the debugger. To do so, first open a `x86 Native Tools Command Prompt for VS 2019`, cd to `C:\Users\klin\SNOLAB\rat` and type:

```auto
C:\Users\klin\SNOLAB\rat>devenv /debugexe yourapp.exe

```

---

<div class="post-metadata">

**Author:** ![kevinlinxc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kevinlinxc/32/21030_2.png) [@kevinlinxc](https://root-forum.cern.ch/u/kevinlinxc)\
**Post date:** [March 4, 2020, 1:29pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/5 "2020-03-04T13:29:36Z")

</div>

I see this memory spike ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/6/c61436b015dda374b38904b5a13e73062d5b188c.png)  
This is what the rest looks like

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/5/0/500c3269295b97a7257544380830a75e6667efe6.png)  
What can I do with this?

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 4, 2020, 1:33pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/6 "2020-03-04T13:33:01Z")

</div>

I see there is an unhandled exception. If you want to try to catch it, you must use the debug version of ROOT and build your app (and anything you want to debug) in debug mode…

---

<div class="post-metadata">

**Author:** ![kevinlinxc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kevinlinxc/32/21030_2.png) [@kevinlinxc](https://root-forum.cern.ch/u/kevinlinxc)\
**Post date:** [March 4, 2020, 1:41pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/7 "2020-03-04T13:41:36Z")

</div>

Can you explain how to do that? Currently I ran the command you gave me, pressed the start button in VS, and then ran my macro in the terminal that appeared

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 4, 2020, 1:43pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/8 "2020-03-04T13:43:44Z")

</div>

Which version of ROOT did you install? How did you compile your application?

---

<div class="post-metadata">

**Author:** ![kevinlinxc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kevinlinxc/32/21030_2.png) [@kevinlinxc](https://root-forum.cern.ch/u/kevinlinxc)\
**Post date:** [March 4, 2020, 1:45pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/9 "2020-03-04T13:45:47Z")

</div>

Root 6.18/04 for Windows. The “application” is a macro. I run it by using “.x macro.cc” in the root terminal, where it is then compiled by root (I think)

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 4, 2020, 1:48pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/10 "2020-03-04T13:48:00Z")

</div>

OK, so download the debug version of ROOT 6.18/04 for Windows, and use `ACLiC` to debug your macro `.x macro.cc++`

---

<div class="post-metadata">

**Author:** ![kevinlinxc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kevinlinxc/32/21030_2.png) [@kevinlinxc](https://root-forum.cern.ch/u/kevinlinxc)\
**Post date:** [March 6, 2020, 3:50pm UTC](https://root-forum.cern.ch/t/memory-other-limiting-factor/38254/11 "2020-03-06T15:50:28Z")

</div>

For anyone else with this issue, the fix was to do “garbage collection” aka  
`delete graph`  
`delete hist`  
at the end of functions so that there isn’t allocated memory being kept for no reason.  
Deleting trees crashes the macro and deleting some other stuff crashes it too so its best to test deleting root objects individually
