简体   繁体   中英

How can I fix this memory leak

If I release the dueDate here I am having BAD_EXCESS in other place of my code. What am I doing wrong here? invoice is a core date object/entity here.

NSDate *deliveryDate = [NSDate dateWithTimeIntervalSinceNow: - oneDayInSeconds * 7];
NSDate *dueDate = [[NSDate date] initWithTimeInterval:(NSTimeInterval) (oneDayInSeconds * 3) sinceDate:deliveryDate]; 
[invoice setDueDate:dueDate];  
//[dueDate release];

Use

[NSDate alloc]

instead of

[NSDate date]

[NSDate date]更改为[NSDate date]分配[NSDate alloc]

As said, change [NSDate date] to [NSDate alloc].

If you are "init"ing you need to "alloc" too.

Alternatively you could do this:

NSDate *dueDate = [NSDate dateWithTimeInterval:sinceDate:]

or even:

NSDate *dueDate = [NSDate date]; dueDate = [NSDate dateWithTimeInterval:sinceDate:]

etc etc... :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM