Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Do not use -retainCount.</h1> <p>The absolute retain count of an object is meaningless.</p> <p>You should call <code>release</code> exactly same number of times that you caused the object to be retained. No less (unless you like leaks) and, certainly, no more (unless you like crashes).</p> <p>See the <a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html%23//apple_ref/doc/uid/20000994-BAJHFBGH" rel="nofollow">Memory Management Guidelines</a> for full details.</p> <hr/> <p>There are a few problems in your code:</p> <ul> <li><p>you aren't following the correct <code>init</code> pattern. You should have a <code>self = [super init...]; if (self) {...}</code> in there somewhere.</p></li> <li><p><code>tempFileName</code> is a <code>retain</code> property and you assign it the result of <code>alloc/init</code>. It will be leaked.</p></li> <li><p>An immutable empty string (<code>[[NSString alloc] init]</code>) is pretty much never useful. And, in fact, <code>stringFromFileAtPath</code> is being leaked (technically -- implementation detail wise there is an empty immutable singleton string and thus, no real leak, but.... still...)</p></li> <li><p>Finally, the crash: your <code>readLine</code> method correctly returns an autoreleased object. Yet, your <code>while()</code> loop consuming the return value of <code>readLine</code> is also <code>release</code>ing that return value, leading to a double-release and an attempt to free that which was already freed.</p></li> </ul> <p>You should "build and analyze" your code. I bet the llvm static analyzer would identify most, if not all, of the problems I mentioned above (and probably some more I missed).</p> <hr/> <p>When building with the analyzer, do you have either "all messages" or "analyzer issues only" selected in the Build window? Because, looking at the code, I'm surprised the analyzer didn't catch the obvious problem with <code>stringFromFileAtPath</code>.</p> <p>Excerpting the code, you have the following lines that manipulate <code>stringFromFileAtPath</code>:</p> <pre><code>NSString *stringFromFileAtPath = [[NSString alloc] init]; .... stringFromFileAtPath = [NSString stringWithContentsOfFile:tempFilePath encoding:NSUTF8StringEncoding error:&amp;error]; .... stringFromFileAtPath = remainContent; .... [stringFromFileAtPath release]; </code></pre> <p>And <code>remainContent</code> is set by:</p> <pre><code>remainContent = [stringFromFileAtPath stringByReplacingCharactersInRange:firstLineChangeLineIncludedRange withString:@""]; </code></pre> <p>You are releasing an autoreleased object. By <em>memory keeps going up</em>, how are you measuring it? Don't use Activity Monitor as it is nearly as useless to developers as <code>retainCount</code> is misleading. Use Instruments.</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. 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.
 

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