Le 19 juil. 08 à 07:20, Cloud Strife a écrit :

Hi, everyone.Assuming there is a Core Animation render tree with many
calayers and complex levels, should I use the iteration function to remove one layer from one layer or there just is some useful function to delete the
whole render tree neatly at once to make the app robust ?

After created and some work to the existing render tree, I want to clean it to release the CPU and memory and GPU it occupied. Because the performance and stability are the main keys of my application. I wrote some ugly code to do that, as expected, the result is very bad, my application crashed ...
:-(

[self cleanWindowContentViewSubLayers:[[[_aWindow contentView] layer]
sublayers ]];


-(void) cleanWindowContentViewSubLayers:(NSArray*)_Layers{

int i, count = [_Layers count];

for(i = 0;i < count; i++){

CALayer* _oneLayer = (CALayer*)[_Layers objectAtIndex:i];

[self cleanWindowContentViewSubLayers:[_oneLayer sublayers]];

//if the _oneLayer is the leaf of the render tree, when iterating the next level of the stack, the for statement won't execute for the _Layers == nil

               //then we can delete it

               [_oneLayer removeFromSuperlayer];

[_oneLayer release];

}


You should not retain each sublayer. When you add a sublayer to a parent layer, as the parent CALayer retain it, you can release it. Like that, when you no longer need your tree, just release the root layer (or remove root layer child) and all sub-child will be released automatically.

Just a details, a var name that starts with an underscore is reserved for Apple class's private ivars (and even if they are reserved, many poeple use them for private ivars too), so you should not use it for local variable and parameters. It's very confusing and make the code hard to understand for people who follow coding guidelines.

http://developer.apple.com/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html







_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to