Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Firstly, can you describe the problem you are trying to solve with this code? I ask because it appears very complex and my initial thought is that simplification will not only clarify what you are doing, but is also likely to solve your leak as well.</p> <p>Secondly, (and I may have this wrong), you only need to retain/release objects if you expect those objects to exist beyond the scope of the method, or you expect that they may be released by some code that you are claling in you method. Based on this, you appear to be over retaining and releasing in your code. I think you can remove a lot of it.</p> <p>Again I may be wrong, but it appears that you will indeed leak. The reason I think so is this - on your first pass you retain some data in <code>dateToReturn</code> which is a local variable. Then you do</p> <pre><code>self.initialStartDateAndTime = [[dateToReturn copy] autorelease]; </code></pre> <p>But this is not releasing <code>dateToReturn</code>. Instead it is releasing the copy of <code>dateToReturn</code>. <code>dateToReturn</code> is still retained. Presuming that you intend to autorelease the copy because <code>initialStartDateAndTime</code> is set with retain, I think you should be doing:</p> <pre><code>self.initialStartDateAndTime = [[dateToReturn copy] autorelease]; [dateToReturn release]; </code></pre> <p>Of course, if you remove the extra retain/release's then this becomes simpler again.</p> <p>The final thing I would suggest is around naming. The problem with code like this is that you have a number of methods and variables, all with very similar names. This can make it difficult to follow and lead to bugs. So ask yourself if you really need this many variables. And can you make your code more readible by changing some of the names.</p>
 

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