Search code examples
objective-cmemory-managementalloc

Is it ok to allocate released object again?


if i did this

Object * myObject = [[Object alloc]init];
[myObject release];

is there anything wrong about allocating my object in next line

myObject = [[Object alloc]init];

again?


Solution

  • No problem at all. [myobject release]; releases the object pointed at by myObject.

    Later, myobject = [[Object alloc] init] will make myobject point to another object.