Error No Memory For Static Root
3 Oct 2008 12:35:37 -0500 Hi Roger, Handling of static variable is one of the current weakness in CINT. To work around the problem simply use this alternative ordering of the code: (or use ACLiC). void read_tree_minimal() { static Double_t energy; TFile *f = new TFile("Ca1Mn47d.lowsanidined.20080506.135053.root"); return; } Cheers, Philippe. Roger Mason wrote: > Hello, > > I'm trying to write a macro to read in values from a TTree in a root > file. The following minimal example fails: > > #include "TFile.h" > #include "TTree.h" > #include "TBrowser.h" > #include "TH2.h" > #include "TRandom.h" > #include "TCanvas.h" > > void read_tree_minimal() > { > > TFile *f = new TFile("Ca1Mn47d.lowsanidined.20080506.135053.root"); > static Double_t energy; > return; > } > > root [0] .x read_tree_minimal.C > Error: No memory for static energy\23b\0 read_tree_minimal.C:12: > > The same macro compiles without error: > > root [1] .x read_tree_minimal.C++ > Info in
Canal
maybe const, in root macro (root ver. 5.18).I received the error: "No memory for http://roottalk.root.cern.narkive.com/97EwDXiL/static-no-memory static..."It is not much important problem for me. I http://stackoverflow.com/questions/641462/can-using-too-many-static-variables-cause-a-memory-leak-in-java may to do it at other way.But this error give some discomfort at work.Best regards,Jan Malinowski//===============================================================/* Random number generator *///===============================================================double Rnd() {const unsigned long a=397204094;const unsigned long b=0;const unsigned long c=2147483647;static unsigned long x1;static unsigned long x2=1.0;double error no R;x1=x2;x2=(a*x1 + b) % c;R=double(x2)/double(c);return R;}//---------------------------------------------------------------int main(){gROOT->Reset();gStyle->SetOptStat(1110);TCanvas* c1 = new TCanvas("c1","RNG",1,1,800,600);TH1D* hist = new TH1D("hist","hrng", 50, 0.0, 1.0);for(int i=0; i<10; ++i){double x=Rnd();hist->Fill(x);}hist->SetTitle("Xmax distr.;Xmax;dN/dXmax");hist->Draw(); // it mean "HIST";c1->Update();}//=============================================================== Rene Brun 2008-10-13 09:55:39 UTC PermalinkRaw Message Delete the statementgROOT->Reset();THIS SHOULD NEVER BE CALLED IN A NAMED MACRO !!!!!Rene error no memory BrunPost by Jan MalinowskiDear Rooters,the function Rnd() (below) good work at many compilers. I have theproblem with static, and maybe const, in root macro (root ver. 5.18).I received the error: "No memory for static..."It is not much important problem for me. I may to do it at other way.But this error give some discomfort at work.Best regards,Jan Malinowski//===============================================================/* Random number generator *///===============================================================double Rnd() {const unsigned long a=397204094;const unsigned long b=0;const unsigned long c=2147483647;static unsigned long x1;static unsigned long x2=1.0;double R;x1=x2;x2=(a*x1 + b) % c;R=double(x2)/double(c);return R;}//---------------------------------------------------------------int main(){gROOT->Reset();gStyle->SetOptStat(1110);TCanvas* c1 = new TCanvas("c1","RNG",1,1,800,600);TH1D* hist = new TH1D("hist","hrng", 50, 0.0, 1.0);for(int i=0; i<10; ++i){double x=Rnd();hist->Fill(x);}hist->SetTitle("Xmax distr.;Xmax;dN/dXmax");hist->Draw(); // it mean "HIST";c1->Update();}//=============================================================== 1 Reply 13 Views Switch to linear view Disable enhanced parsing Permalink to this page Thread Navigation Jan Malinowski 2008-10-13 09:59:19 UTC Rene Brun 2008-10-13 09:55:39 UTC about - legalese Loading...
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Can using too many static variables cause a memory leak in Java? up vote 36 down vote favorite 11 If my application has too many static variables or methods, then as per definition they will be stored in heap. Please correct me if I am wrong 1) Will these variables be on heap until application is closed? 2) Will they be available for GC at any time? If not can I say it is a memory leak? java memory-management memory-leaks share|improve this question edited Mar 13 '09 at 6:30 sharptooth 109k50317708 asked Mar 13 '09 at 4:27 harshit 2,962125085 add a comment| 5 Answers 5 active oldest votes up vote 60 down vote accepted Static methods are just methods, they are not stored on the heap, they just don't get to use a "this" parameter. Static variables serve as "roots" to the GC. As a result, unless you explicitly set them to null, they will live as long as the program lives, and so is everything reachable from them. A situation is only considered a memory leak if you intend for the memory to become free and it doesn't become free. If you intend for your static variable to contain a reference to an object for part of the time, and you forget to set it to null when you're done with that object, you would likely end up with a leak. However, if you put it in the static variable and intend for it to be there for as long as the program is running, then it is most definitely