Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: Is there any way to find out what kind of object resides at a particular memory address?

Coming from Java and Python, I am not so well versed in memory management, but is there any way to find out what kind of object resides at a particular memory address?

I am asking because my application terminated with a cryptic message that reads:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber encodedURLParameterString]: unrecognized selector sent to instance 0x164840'

and would like to get some clues as to what is going wrong.

And if that is not possible, some debugging techniques for such error messages would be greatly appreciated.

Thanks in advance!!

EDIT: Follow Up Concern (MOVED HERE)

After some investigation of the framework that I have been using, I came across something that I don't really understand.

If I have a method

- (void) myMethod:(NSString *)string {
    [Object anothermethodWithString:string];
}

and I call

[Object myMethod:@"this is a string"];

Do I need to do something like

NSString *string2 = [[NSString alloc] initWithFormat:@"%@", string];
[Object anothermethodWithString:string2];
[string2 release];

instead of the way I had myMethod before? It seems like the string I passed through the parameter of my method got released somewhere, and doing that solves my problem. I guess I don't really understand what exactly @"string" does in terms of memory. Is it like an auto-released NSString?

like image 335
Ayaka Nonaka Avatar asked Jan 26 '26 11:01

Ayaka Nonaka


1 Answers

well, from the error, the object type at that memory address is NSDecimalNumber. You got an error because you called encodedURLParameterString on a NSDecimalNumber which does not have a method with that name.

like image 106
Jesse Naugher Avatar answered Jan 28 '26 00:01

Jesse Naugher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!