循环中大量生成的自动释放autorelease对象,可以考虑使用autorelease pool封装

循环中大量生成的自动释放autorelease对象,可以考虑使用autorelease pool封装

代码范例:

C代码  收藏代码
  1. for(UIView *subview in bigView.subviews) {  
  2.     // 使用autorelease pool自动释放对象池  
  3.     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
  4.   
  5.     UIImageView *imageView = (UIImageView *)subview;  
  6.       
  7.     // subview处理代码  
  8.     .......  
  9.   
  10.     // 销毁自动释放对象  
  11.     [pool  drain];  
  12. }  
for(UIView *subview in bigView.subviews) {     // 使用autorelease pool自动释放对象池     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];      UIImageView *imageView = (UIImageView *)subview;          // subview处理代码     .......      // 销毁自动释放对象     [pool  drain]; }

 自动释放对象池把每个循环内生成的临时对象使用完后立即释放

posted on 2011-08-05 09:56  倾听林语  阅读(290)  评论(0)    收藏  举报

导航