RE: TClonesArray stomping on the stack

From: Philippe Canal <>
Date: Fri, 08 Dec 2006 13:45:01 -0600


This is the expected behavior.

   delete bigArr[chan];

is semantically incorrect and will lead to an expected seg fault. The memory initialized via 'new(bigArr[chan])' is __owner__ by the TClonesArray and the TClonesArray will delete it as part of its own destructor. Doing another expliclty delete will lead to a double detele.


-----Original Message-----
From: [] On Behalf Of George Locke
Sent: Friday, December 08, 2006 1:02 PM
Subject: [ROOT] TClonesArray stomping on the stack


running 5.13/05 compiled from source using MSVC 8 on windows 2000. I am compiling this code in MSVC 8

the following code generates seg fault when it exits the PHA_3 subroutine (after printing "this test is now complete", and it doesn't print "exit PHA"). What is going on?

note that when TCLONES is defined 0 there is no seg fault, it prints exited PHA. I tried not deleting the members of bigArr but that was no help.


// root includes
#include "TH1I.h"
#include "TClonesArray.h"

#define TCLONES 1


void PHA_3(); // minimum save histograms function

int main(int argc, char **argv) {

	printf("exited PHA\n\n");
	return 0;


void PHA_3() {

        printf("We ahve entered PHS\n\n");

		Create the data storage
	const short HIST_SIZE = 256;
	const short NUM_CHAN = 8;

	char name[10];
	char title[30];
	short chan;

TClonesArray bigArr("TH1I", 8); for (chan=0; chan<NUM_CHAN; chan++) { sprintf_s(name, "bigHist%d",chan); sprintf_s(title, "Testing a big Histogram %d", chan); new(bigArr[chan]) TH1I(name,title,HIST_SIZE,0,HIST_SIZE); } for (chan=0; chan<NUM_CHAN; chan++) { delete bigArr[chan]; printf("\t deleted %d\n\n",chan); }

	printf("this test is now complete\n");



Thanks for your help,
George Received on Fri Dec 08 2006 - 20:45:21 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:02 MET