The main plot The problem of memory consumption with an arc

I am creating an application related to graphics with ARC enabled, in which there are two different views on the chart: -One small view that I have to change with the click of a button (using the reset data). The second view is the large one, on which the schedule changes when buttons are pressed, such as "1 day", "3 days", "5 days".

The problem that I encountered is that after 15-20 minutes of continuous use of the application it crashes with the log .... "CAAnimation could not allocate bytes." When I analyzed in the profile, I found out that when a small graph loads live bytes of bytes at 2-3 mb, and when large graphs load, live bytes jump to 4-5 mb and live bytes, they never go down. I disabled all graph objects when exiting the view, but even then the memory was not released.

when switching to the following graph, I call this method:

-(void)removePlot { for(CPTPlot* plot in [graph allPlots]) { plot.dataSource = nil; plot.delegate = nil; [plot deleteDataInIndexRange:NSMakeRange(0, plot.cachedDataCount)]; [graph removePlot:plot]; } } 

and when exiting the view, I call this method:

 -(void)removeGraph { [axisSet removeFromSuperlayer]; axisSet=nil; [self removePlot]; generationPlot=nil; [graph removePlotSpace:plotSpace]; plotSpace=nil; [graph removeFromSuperlayer]; graph=nil; [hostView removeFromSuperview]; hostView=nil; headerList=nil; graphDetailList=nil; graphList=nil; dataList=nil; plotsArray=nil; } 

Many people have encountered this problem before, but the answer will not work for me yet. If anyone has any ideas on this ... please help.

+4
source share
1 answer

Try reading this, it may be useful.

https://developer.apple.com/library/ios/releasenotes/objectivec/rn-transitioningtoarc/introduction/introduction.html

Also, consider the @autoreleasepool mechanism that ARC provides to limit the maximum amount of memory.

Also, make sure that the methods you call invoke. Sometimes we write cleaning procedures, but they are not called !:-)

In addition, you specify the code as:

axisSet = zero generationPlot = zero ... etc ...

what type of axisSet? what type of generationPlot? Global variable If they are not NSObjects (and sometimes even if they are), setting them to nil may not be the proper way to free them.

Consider making some of them @property and giving them the appropriate qualifiers (i.e. strong ones, etc.), then some of your memory usage might be a little clearer. If you have several static or global variables that can cause some confusion.

Hope this helps.

0
source

All Articles