He had just started to learn object-C development, is still in the theoretical stage, seeing autorelease this thing.
Is to say when the release is variable automatic variable pool will release the pool.
Assuming a function call code is usually seen
void Fun1 ()
{
NSAutoreleasePool * pool;
pool = [[NSAutoreleasePool alloc] init];
ClsA * A = [[ClsA alloc] init];
/ / A do sth ...
[A autorelease];
[Pool release];
return;
}
Since the automatic variable pool is only released when the release of resources, whether the code can be changed;
void Fun2 ()
{
NSAutoreleasePool * pool;
pool = [[NSAutoreleasePool alloc] init];
ClsA * A = [[[ClsA alloc] init] autorelease];
/ / A do sth ...
[Pool release];
return;
}
If the definition of variables when they are done, is it easier to avoid a memory leak?
But you do not see this kind of usage, why?
Solving ...
Reply:
Manual RELEASE higher than autorelease performance.
Reply:
Well, I know the manual release of more efficient
I'm just curious to autoease.
Why not allocated directly when the autorelease?
But also because the actual release at the end of the code of conduct will be, ah ~
Reply:
LZ is still a serious look at the concept and application of autoease it.
This is basic knowledge areas not proposed to discuss, there is no discussion.
Reply:
Usefulness of the two codes you gave no difference. . .
autorelease just a tag that identifies this thing will automatically release
release pool
No need to release yourself manually. . .
Reply:
Because just think the same is
Then, if a statement is a direct write, not that much lower forgot autorelease possible?
Just do not understand why other people have not seen the code this way?
In place can autoreleaseSuch a statement is written. What's shortcomings did not?
Reply:
It can be directly assigned autoRelease.
Written just not the same, the same, so I sometimes write, write nothing wrong.
Reply:
Two written the same, just more line of code, and less line of code. There may be written, easy to alloc and release or autoRelease correspond well to find memory leaks
No comments:
Post a Comment