MyClass *var = [[MyClass alloc]initWithSomeNumber:15];
[self addChild:var];
[self removeChild:var cleanup:YES];
Do I have to call release for var? Or does the removeChild method already takes care of such? Is there a way to create var without having to use alloc? I heard that there is a class method for nodes called node. But it doesn’t accept parameters (and as you can see I need to pass the integer 15).
Yes, it is one of the rules defined in the Memory management policy
You use
allocto allocate space forvar, which will set thevarreference counter to 1. NO matter how many other objects claim ownership after this (by sendingretain) you must sendreleaseonvarto decrement the reference counter by 1. Otherwise, the reference counter will never reach 0 which means that the memory used forvarwill never be deallocated, i.e. end up with a memory leak.