Leonardo Marques
Leonardo Marques

Reputation: 3951

Variable memory address attribution EXEC_BAD_ACESS

I have an allocated object where its attributes are store in the following memory places: Memory status

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.

EXEC_BAD_ACESS

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: DownloadFile

EDIT2

init function: enter image description here

EDIT3 date parameter:

date

Upvotes: 0

Views: 85

Answers (1)

Paul.s
Paul.s

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

Related Questions