"Exception: bad allocation" error

I write a code, and run it as following:

root [0] .L TD.C
root [1] coinyb()

coinyb does a group of function as following

{
coin();
coin();
coin();
coin();

coin();
}

as the result shows, after running coin() four times; the program stops and give me “Exception: bad allocation” error.

Could you please help me to solve this problem?

Link of file to run TD.C: 1drv.ms/u/s!AtQQQjEImW1Wg9tD4PD4bngOQFpMyQ

Thank you very much,

Here is my root version: ROOT 5.34/32 (v5-34-32@v5-34-32, Jun 23 2015, 17:58:02 on win32)
TD.C (4.26 KB)

.
TD.C (4.38 KB)

Dear Pepe,

Thank you very much,

As I understand, root doesn’t release the memory until we manually delete it, isn’t it?

ROOT 5 User’s Guide -> Object Ownership