HelloMoon
HelloMoon

Reputation:

What would happen if a weak referenced object gets deallocated from memory and I try to fetch it from an NSValue object?

I assign an object to an NSValue like this:

[NSValue valueWithNonretainedObject:myObject];

What happens if that object gets deallocated from memory, and then I try to pull it out from that NSValue? Would the reference be nil? How could I check if the object is still there? Or would the app just crash when something like this happens?

Upvotes: 1

Views: 85

Answers (1)

Daniel
Daniel

Reputation: 22405

it would most likely crash, if you try and access the value of a freed object it would probably crash i think, or return nil, why dont you give it a try? :) seems pretty simple to do

Upvotes: 2

Related Questions