objective c - Foundation memory management for properties -
for project not using arc, assuming have property on class:
@property (assign) cgpathref pathref;
and have method updating path reference @ point, example:
uibezierpath *bezierpath = [uibezierpath bezierpathwithovalinrect:rect]; self.pathref = cgpathcreatecopy(bezierpath.cgpath);
in dealloc, doing follows:
- (void)dealloc { cgpathrelease(self.pathref); self.pathref = nil; [super dealloc]; }
when running static analyser i'm getting memory advice line using cgpathrelease
:
incorrect decrement of reference count of object not owned @ point caller.
i thought onto here https://developer.apple.com/library/mac/qa/qa1565/_index.html seems explaining how hand off foundation objects core animation apis.
can advise on this, how can manage foundation object without static analyser warning?
you don't own return value of property accessor. use instance variable instead.
cgpathrelease(_pathref);
alternatively (and preferably), can implement accessor methods , include memory management.
- (void)setpathref:(cgpathref)val { if (_pathref) { cgpathrelease(_pathref); _pathref = null; } if (val) { _pathref = cgpathcreatecopy(val); } }
Comments
Post a Comment