Question

Objective c has release method. I want to create my own method that duplicate objective c method. But I don't know hot to free a memory.

-(void) release
{
 if(retainCount == 1)
 {
  [self freeMemory];
 }
 else
 {
  retainCount --;
 }
}

-(void) freeMemory
{

} 
Was it helpful?

Solution

The short answer is that you would call [self dealloc], but you really shouldn't be doing stuff like this, ever ever ever. Under ARC it's not even possible to write this kind of code.

Your method exactly duplicates the functionality of the release method that your class will already have inherited from NSObject, so it's very difficult to see what the point is.

If you want to do something extra when release is called, why not just call [super release]?

Can you explain what it is you want to do at a higher level - maybe there's an alternative approach?

OTHER TIPS

In your freeMemory function you should release all retained class members and that's it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top