Error No Memory For Static
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
installing and running ROOT here. Please post bug reports in Jira. Moderator: rootdev Post Reply Search Advanced search First unread post • 5 posts • Page 1 of 1 PedroGordo Posts: 3 Joined: Fri Dec 05, 2008 14:10 Contact: Contact PedroGordo WLM Memory can't handle a static https://root.cern.ch/root/roottalk/roottalk08/0865.html value? Quote Unread postby PedroGordo » Thu Dec 18, 2008 13:43 Hello! I'm trying to run this script, but when I try to it says: Warning: Automatic variable Int i is allocated light1.cpp:35: Error: No memory for static Int i\0\0 light1.cpp:35: *** https://root.cern.ch/phpBB3/viewtopic.php?t=7812 Interpreter error recovered *** Since it's just a static value isn't it a bit odd that there's no memory for it? This is my script, the static value it's the ProcessTracks part: TGeoManager *geom = new TGeoManager("geom","Optics Demo"); Bool_t Ray=false; Bool_t Lenses=true; Int_t MAXPOINT=10; gSystem.Load("libPhysics.so"); void light1() { DefineGeometry(geom); geom->InitTrack(0,0,35,0,0,1); ProcessTracks(geom); for (double r=20; r<=70 ; r+=10) { for (double phi=0; phi<2.0*TMath::Pi(); phi+=TMath::Pi()/2) { Double_t th=0; geom->InitTrack(r*cos(phi),r*sin(phi),-99,sin(th)*cos(phi),sin(th)*sin(phi),cos(th)); ProcessTracks(geom); } } if (Ray) { geom->DrawTracks(); geom->GetTopVolume()->Raytrace(); } else { geom->SetNsegments(125); geom->GetTopVolume()->Draw("ogl"); DrawTracks3D(geom); } } void ProcessTracks(TGeoManager *geom){ TVector3 point,dir,norm; point.GetXYZ(geom->GetCurrentPoint()); dir.GetXYZ(geom->GetCurrentDirection()); static Int_t i=0; Int_t tid=geom->AddTrack(i,22,new TParticle()); geom->SetCurrentTrack(tid); TVirtualGeoTrack *track = geom->GetCurrentTrack(); if (i == 0) track->SetLineColor(kBlue); else track->SetLineColor(kRed); track->AddPoint(point[0],point[1],point[2],0); // ********* superficies seguintes ************************** for (int j=1; j<=MAXPOINT ; j++) { geom->SetStep(1); geom->
Dear Rooters, the function Rnd() https://root.cern.ch/root/roottalk/roottalk08/0894.html (below) good work at many compilers. I have the problem http://stackoverflow.com/questions/641462/can-using-too-many-static-variables-cause-a-memory-leak-in-java 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 no 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; error no memory 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(); } //=============================================================== Received on Mon Oct 13 2008 - 11:47:01 CEST This message: [ Message body ] Next message: Rene Brun: "Re: PROBLEM: TObjArray and *** Break *** segmentation violation" Previous message: Roberta Ferretti: "PROBLEM: TObjArray and *** Break *** segmentation violation" Next in thread: Rene Brun: "Re: static - no memory" Reply: Rene Brun: "Re: static - no memory" Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ] This archive was generated by hypermail 2.2.0 : Mon Oct 13 2008 - 17:50:02 CEST
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 not a leak, it is more likely a "permanent singleton". If the object got reclaimed while you wanted it to still exist, that would have been very bad. As for your question about the heap: All objects i