Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does NSValue free its value when freed?

Have a look at this pseudocode:

void* magicpointer = malloc(OVER_NINE_THOUSAND);
NSValue* v = [NSValue valueWithPointer:magicpointer];
[v release];

When v is released, does magicpointer get freed as well, or do I have to do that manually? I am using manual reference counting.

like image 903
Georges Oates Larsen Avatar asked Dec 20 '25 05:12

Georges Oates Larsen


2 Answers

It doesn't get freed - NSValue is just a wrapper so you can treat arbitrary values as objects. It doesn't do anything with the wrapped pointer.

No, NSValue won't.

Sounds like you might want to use NSData, it can free it's pointer when it's released:

    void* magicpointer = malloc(OVER_NINE_THOUSAND);
    NSData *d = [NSData dataWithBytesNoCopy:magicpointer
                                     length:OVER_NINE_THOUSAND
                               freeWhenDone:YES];
    //d is autoreleased, so no need to -release it.
like image 36
Vincent Gable Avatar answered Dec 22 '25 21:12

Vincent Gable



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!