Reputation: 3951
I have an allocated object where its attributes are store in the following memory places:
When I make a simple attribution of the NSDate
attribute to a variable it gives me an EXEC_BAD_ACESS
.
As you can see from the first image only the date attribute and the fileDate
variable have different addresses.
Am I making some pointer related error?
The other 2 attributes are assigned correctly to the variables, it only happens with the NSDate
so maybe I'm missing some detail about NSDate
.
EDIT1
DownloadFile
definition:
EDIT2
init function:
EDIT3 date parameter:
Upvotes: 0
Views: 85
Reputation: 38728
Is there any reason why you are not using ARC? There are quite a few memory management errors there causing leaks and one that should cause your crash.
NSDate *dateFromString = [dateFormatter dateFromString:receivedDate];
returns an autoreleased NSDate
so when you then call the additional
[dateFromString autorelease];
you are overreleasing the NSDate
hence your crash.
[pFile setDate:[[NSDate alloc] init]];
is a memory leak. Going through the setter setDate:
will cause pFile
to take a +1 retain on the date, which it should release in it's dealloc
. The [[NSDate alloc] init]
call returns a date object with +1 but is then never released elsewhere.
You can fix this either with
[NSDate date]
Or
[[[NSDate alloc] init] autorelease];
The first option is preferred
Upvotes: 3