I ' veinheritedasubstantialqt 5项目,wheretheaccumulativememoryleakageisbecomingaseriousissue.(memoryleakageshouldrarelyysue )
thisguireadsimagedataintoobjectsofavoxelclass,tobedisplayedgraphically.thedatacomeseitherfromfileorbuffer (
when an image is自读取文件,cvoxelisinitializedusingqvector.resize (0)。
When an image save to file is opened,alocalvoxelpointeriscreatedandpushedtotheendofcvoxel,onceforeverypixelsoloopingoverallllrowsansansatind
for(irow=0; iRow nRows; iRow )
{
for(icol=0; iCol nCols; iCol )
{
Voxel *v=new Voxel;
//codeforreadingdataintocvoxelremovedhere
.
}
}
courtesyoftheusefulcommentsbelow,I ' venowhadsomesuccessinseeingmemoryusagedecreaseinthewindowstaskmanager,bynestingdestestrurur
for(irow=0; iRow nRows; iRow )
{
for(icol=0; iCol nCols; iCol )
{
delete cVoxel[iRow][iCol];
}
}
Ideally,amajorrewriteisthebestsolution.butintherealworld,I ' llhavetotryandfixthebiggerleaksandhopethat ' senoughuntilthat
I ' velookedatmemoryleakagesinvoxelitself,but there's nothing obvious there。
myresearchrevealsthatlookingatthewindowstaskmanagerformemoryconsumptionisn ' tentirelyreliable (win7isn ' tareal-timeos ) . butifopeningafileincreasestheapplicationmemoryconsumptionfrom 16 MTO 81.5 m, thensurelythereshouldbesomememorydecreaseiftheallocacation if I keep opening and shut images,the app ' smemoryconsumptionkeepsincreation
Right now,there ' snoattempttoreleaseanymemoryassigned (usingthenewoperator ) TOC voxel.ihavetriedafewapproaches (andreadtted
--- -编辑--- -
apologiesforthemessyad-hodcommentingbelow,butthisiscertainlyhelpingmereducethememoryleakages (completestoppagewillhopefuleages
I ' veeditedin-lineaboveto (hopefully ) make this post clearer,andremovedmybestcaseeffortasithadnoimpactonthememoryleak.thh
ialsoneedtoinvestigate @ Richard citter (sp? ) polymorphism关联的suggestion。
--- EDIT3 ---
Removed Edit2,postedthat(new ) question separately here。
Also,I ' mprettyconfidenttheanswerbelowshouldfixthisquestion-ijustneedtofigureouthowtouseqvector.resize (
解决方案
@ someprogrammerdude : you got me9/10 towardsthesolution.id on ' tknowwhetherishouldedityouranswerorusethis,so moderator(s ()
As outlined in a connected SO post,idecidedagainstsmartpointersintheend.theabovesolutionintroduced (格式) )。 theissueofthecompilertryingtoreferenceadeletedfunction.otherwiseitiscorrectwithacoupleofmodifications 3360
Initialisation:
内存评估:
{
for(intI=0; i rows; I )
{
for(intj=0; 日寇; j )
{
Voxel *v=new Voxel;
}
}
}
finallydtorreleasingthememory :
int iRow,iCol;
for(irow=0; iRow rows; iRow )
{
for(icol=0; ICOL; iCol )
{
delete cVoxel[iRow][iCol];
}
}