I originally built my TBB code on Windows and it worked fine. Today I moved my code to Linux system (OpenSUSE 64 bit).
When I tried to run it, the program always stopped after some iterations. I wonder whether it is because the system run out of memory.The part of code is put below.
SolverP2 Improve(&inst,&mysolution,StartSolT1,&P1Queue,&P2Queue,&P3Queue,iterControl,exchangeControl,&stopControl );
task_list tl;
P2MainTask& a=*new(task::allocate_root()) P2MainTask(&Improve);
tl.push_back(a);
SolverP2T2 Thread2(&inst,&mysolution,StartS开发者_JAVA技巧olT2,&P1Queue,&P2Queue,iterControl,exchangeControl,&stopControl );
P2Thread2Task& b=*new(task::allocate_root()) P2Thread2Task(&Thread2);
tl.push_back(b);
SolverP2T3 Thread3(&inst,&mysolution,StartSolT3,&P1Queue,&P3Queue,iterControl,exchangeControl,&stopControl );
P2Thread3Task& c=*new(task::allocate_root()) P2Thread3Task(&Thread3);
tl.push_back(c);
Shaking shakeSol(&inst,&mysolution,StartSolT4,&P4Queue,&stopControl );
ShakingTask& d=*new(task::allocate_root()) ShakingTask(&shakeSol);
tl.push_back(d);
cout<<"task deine finished"<<endl;
task::spawn_root_and_wait(tl);
cout<<"task start finished"<<endl;
Could anyone tell me how to solve this problem? how can we release the memory defined by new for reuse? Thanks!
Use the delete
operator to clean up memory that's no longer being used, but you'll also have to declare some pointer variables since you didn't keep the original pointers:
P2MainTask *pa = &a;
delete *pa;
P2Thread2Task *pb = &b;
delete *pb;
P2Thread3Task *pc = &c;
delete *pc;
精彩评论