views:

29

answers:

0

Lets consider the following scenario:

I have a class , where I have a member variable named "sampleArray". I have only one Autorelease pool as part of my App.(main.m).

I add some objects to "sampleArray" using a convenience constructor in a method named "Method1".

Based on autorelease concept(NSAutoreleasePool), the object would be no longer available beyond the scope of the "Method1". And when we use it in other functions the program would crash. But the memory is released only when the autorelease pool is released. I find this to be contradicting. During debugging , I have found the autorelease variable having some memory address (not 0x0 as in released objects). Then why does the app crashes when I try to access it?

Am I misunderstanding any concept here? According to Autorelease pool, the object would be released, only when Autorelease pool is released. My "sampleArray" variable is not released and it holds a memory address. But then, why can't I access its value.(If I do, it crashes)?