Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So looking at these one by one, focusing on the memory issues and not the overall strategy here:</p> <p><code>NSString *finalword= [[NSString alloc]init ];</code></p> <p>Here you alloc/init a new immutable and empty NSString, and then you end up overwriting the pointer to this later anyway. You should just delete this line. And then you'll need to move the declaration down a few lines to this:</p> <p><code>NSString *finalword = [wordoftheday substringFromIndex:[startfrom length]];</code></p> <p>Then you have:</p> <p><code>NSString *startfrom = [[NSString alloc] initWithFormat:@"word%i",i+1];</code></p> <p>This one you need to release later. Or just change it to:</p> <p><code>NSString *startfrom = [NSString stringWithFormat:@"word%i",i+1];</code></p> <p>Then you have:</p> <p><code>NSString *wordoftheday = [[NSString alloc]init ];</code></p> <p>Same story as finalword. Except that you do need to define this variable so you can pass it to the scanner later. So change it to:</p> <p><code>NSString *wordoftheday = nil;</code></p> <p>And lastly, you can release 'file'. That is fine. But you don't want to release 'wordoftheday' or 'finalword' because you don't own those strings. You did not create them yourself.</p> <p>And one other note:</p> <p><code>if(error)</code></p> <p>That is not the correct way to check for an error in loading 'file'. You should check the return from the method and then look for an error if and only if the return value was nil. So change that line to:</p> <p><code>if(!file)</code></p> <p>(OK, that wasn't really a memory issue, but a bug I did notice.)</p> <p>I think that's all of it at least as far as memory issues. I hope that helps.</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.
 

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