Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For the benefit of others who find themselves vexed by memory leak problems I'm going to provide the answer to my problem here because the sleuthing process may help you.</p> <p>In the middle of the code listing you can see where I inform the compiler that I will soon be using two CGPathRefs, initially inside the scope of an if/then/else, so I needed them allocated (?) outside that block so they are local to my routine.</p> <pre><code>CGPathRef tmpRightEdgePath2; CGPathRef tmpLeftEdgePath2; </code></pre> <p>By changing those to:</p> <pre><code>CGPathRef tmpRightEdgePath2 = NULL; CGPathRef tmpLeftEdgePath2 = NULL; </code></pre> <p>That cleared up the two leaks being reported as occurring during the if/then/else statement.</p> <p>So now my only two remaining leaks are reported inside the if (done) {} block.</p> <p>In Instruments, looking at the Leaks tool, the Cycles &amp; Roots -> Leak Cycles -> foo History I see where the 10 memory events end with a RefCt being 1, so clearly a leak:</p> <pre><code># Category Event Type RefCt ResponsibleLibrary Responsible Caller 0 NSMutableRLEArray Malloc 1 Foundation -[NSConcreteAttributedString initWithString:attributes:] 1 NSMutableRLEArray Release 0 Foundation -[NSConcreteAttributedString dealloc] 2 NSMutableRLEArray Free 0 Foundation -[NSRLEArray dealloc] 3 CGPath Malloc 1 CoreGraphics CGTypeCreateInstance 4 CGPath CFRelease 0 my app my routine 5 CGPath Free 0 my app my routine 6 CGPath Malloc 1 CoreGraphics CGTypeCreateInstance 7 CGPath CFRelease 0 my app my routine 8 CGPath Free 0 my app my routine 9 CGPath Malloc 1 CoreGraphics CGTypeCreateInstance </code></pre> <p>So at some point after I thought I was done manipulating my paths there had to be another CGCreateCopy... style call occurring, since a Malloc was called <em>after</em> I had released everything. So by using search/find I worked my way forward through the drawing code and found a last CGPathCreateCopyByTransforming:</p> <pre><code>CGAffineTransform slightUp = CGAffineTransformMakeTranslation(0, - lineThickness * 2 ); leftEdgePath = CGPathCreateMutableCopyByTransformingPath(leftEdgePath, &amp;slightUp); rightEdgePath = CGPathCreateMutableCopyByTransformingPath(rightEdgePath, &amp;slightUp); </code></pre> <p>Which are guaranteed leaks since the retain count went up by one during that copy. So I reworked those to be:</p> <pre><code>CGAffineTransform slightUp = CGAffineTransformMakeTranslation(0, - lineThickness * 2 ); CGMutablePathRef finalLeftEdgePath = CGPathCreateMutableCopyByTransformingPath(leftEdgePath, &amp;slightUp); CGPathRelease(leftEdgePath); CGMutablePathRef finalRightEdgePath = CGPathCreateMutableCopyByTransformingPath(rightEdgePath, &amp;slightUp); CGPathRelease(rightEdgePath); </code></pre> <p>And then I changed my CGContextAddPath() to match the new "final" paths, and also the final release calls to release the "final" versions and I am leak free!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload