2

EDIT

Apparantly it seems to be a bug in sprite kit / box2d: SKPhysicsBody bodyWithPolygonFromPath memory leaks

I was just too naive to think that apple wouldn't have leaks :D

CGMutablePathRef path = CGPathCreateMutable();

CGPathMoveToPoint(path, NULL, 3 * scale - offsetX, 44 * scale - offsetY);
CGPathAddLineToPoint(path, NULL, 69 * scale - offsetX, 52 * scale - offsetY);
CGPathAddLineToPoint(path, NULL, 80 * scale - offsetX, 14 * scale - offsetY);
CGPathAddLineToPoint(path, NULL, 45 * scale - offsetX, 2 *scale - offsetY);
CGPathAddLineToPoint(path, NULL, 1 * scale - offsetX, 16 *scale- offsetY);

CGPathCloseSubpath(path);

self.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];
CGPathRelease(path);

Am I missing something? I release the object, but instruments complaints about memory leaks..

75%

CGPathMoveToPoint(path, NULL, 3 * scale - offsetX, 44 * scale - offsetY);

25%

self.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];
Community
  • 1
  • 1
chrs
  • 5,906
  • 10
  • 43
  • 74

2 Answers2

0

The Apple docs state: "Decrements the retain count of a graphics path". Wether or not the path is released is based on the current retain count. If something else retains the path then it will not be released. What else could be retaining the path, how about:

self.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];

If you need to see where retains, releases and autoreleases occur for an object use instruments:

Run in instruments, in Allocations set "Record reference counts" on on (you have to stop recording to set the option). Cause the problem code to run, stop recording, search for there ivar of interest, drill down and you will be able to see where all retains, releases and autoreleases occurred.

enter image description here

zaph
  • 111,848
  • 21
  • 189
  • 228
  • http://stackoverflow.com/questions/20134891/skphysicsbody-bodywithpolygonfrompath-memory-leaks Apparantly a bug in sprite kit. – chrs Feb 28 '14 at 00:45
0

Almost certainly you are leaking the SKPhysicsBody or self, but it's also possible that you're extracting the path elsewhere and over-retaining it. Instruments only keeps track of when things are allocated. It can't detect when you made a mistake in releasing things. So if you leak the entire physicsBody, it will show up as "memory that was allocated in this area of the code."

Rob Napier
  • 286,113
  • 34
  • 456
  • 610