The rule of thumb when it comes to iOS memory management:
For each alloc , retain , copy or new , you must have a corresponding release or autorelease .
In fact, you flow in several places. In your header, retain your date objects, and then in the dealloc method, you release them. It's right. However, in your assignDate methods, you cannot release a copy or a stored date. While [NSDate date] auto-implemented, you save and copy them yourself.
There is no reason to use your assignCurrentDate methods. In the init method, you can simply do something like the following:
self.currentDate1 = [NSDate date];
What is it.
Edit: (Well, that is not the case.)
As Jim notes in the comments:
Saving in the header means that the synthesized installer for these properties will save the objects assigned to them. But if you look at the assign * methods, you will see that only the CurrentDate3 property actually uses the property. The rest is assigned directly to ivar, bypassing the synthesized setter, so they are not saved when assigned.
Moshe
source share