首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏菩提树下的杨过

    objective-C 的内存管理之-自动释放池(autorelease pool)

    * pool = [[NSAutoreleasePool alloc] init]; //insert code here... ; [pool drain]; return 0; } 即:xcode为开发者写的代码外层包了一层NSAutoreleasePool。 4、不要把大量循环操作放到同一个NSAutoreleasePool之间,道理同上,这样会使池中有大量对象,导致程序在运行时占用较多内存。 比如下面这段代码: int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool 可以改进为下面这样: int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool

    1.4K100发布于 2018-01-22
  • 来自专栏Elton的技术分享博客

    iPhone/Mac Objective-C内存管理教程和原理剖析(一)基本原理

    autorelease pool的真名是NSAutoreleasePoolNSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 6.2 NSAutoreleasePool内部包含一个数组(NSMutableArray int main (int argc, const char *argv[]) { NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] 例如: int main (int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init *pool = [[NSAutoreleasePool alloc] init]; int i, j; for (i = 0; i < 100; i++ ) { NSAutoreleasePool

    49410发布于 2021-01-26
  • 来自专栏Chasays

    Objective-C 学习记录6--dictionary

    import <UIKit/UIKit.h> #import "MyClass.h" int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //添加我们的测试代码 NSDictionary import <UIKit/UIKit.h> #import "MyClass.h" int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //添加我们的测试代码 //创建词典对象,初始化长度为

    65930发布于 2019-06-26
  • 来自专栏程序员Gank

    《Objective-C-高级编程》干货三部曲(一):引用计数篇

    废弃NSAutoreleasePool对象。 ? 所有调用过autorelease方法的对象,在废弃NSAutoreleasePool对象时,都将调用release方法(引用计数-1): NSAutoreleasePool *pool = [[NSAutoreleasePool 也就是说,如果有大量的autorelease变量,在NSAutoreleasePool对象废弃之前(一旦监听到RunLoop即将进入睡眠等待状态,就释放NSAutoreleasePool),都不会被销毁 NSAutoreleasePool *pool = 取得正在使用的NSAutoreleasePool对象 if (pool ! 使用@autorelease块代替NSAutoreleasePool ARC下须使用使用@autorelease块代替NSAutoreleasePool。 6.

    2.1K40发布于 2018-07-23
  • 来自专栏全栈程序员必看

    Objective-C 内存管理之 _ARC

    NSObject提供的方法,此方法在某一个预定的时候,想对象发送 release 消息,返回值是接收消息的对象.实际上当给一个对象发送 autorelease 消息的时候,就是将这个对象加入到自己主动释放池( NSAutoreleasePool 如: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; for ( int i = 0; i < 1000000; i++ descripton if ( i % 100 == 0) { [pool release]; pool = [[NSAutoreleasePool 不能再使用 NSAutoreleasePool 对象, ARC 提供了@ autoreleasepool 块来替代它,这样更加有效率.

    81110编辑于 2022-07-08
  • 来自专栏Code_iOS

    Objective-C 内存管理(上)学习笔记

    自动释放池:在自动释放池结束时,系统自动为里面的对象发送一条release消息(when the pool itself is drained) 要使用自动释放池就要使用NSAutoreleasePool NSAutoreleasePool NSAutoreleasePool它的方法 ? 使用方法: 创建一个NSAutoreleasePool对象 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 添加要释放的对象进NSAutoreleasePool NSString alloc] initWithstring:@"objective-c pool"]; [obj autorelease];或[pool addObject:obj]; --- 1 释放NSAutoreleasePool

    1K20发布于 2018-09-04
  • 来自专栏菩提树下的杨过

    objective-C中如何判断一个类中有没有定义某个方法

    import <Foundation/Foundation.h> #import "Sample.h" int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Sample *s = [Sample new]; if ([s respondsToSelector

    1.5K90发布于 2018-01-22
  • 来自专栏梧雨北辰的开发录

    iOS内存管理-深入解析自动释放池

    1.1 MRC下使用自动释放池 在MRC环境中使用自动释放池需要用到NSAutoreleasePool对象,其生命周期就相当于C语言变量的作用域。 对于所有调用过autorelease方法的对象,在废弃NSAutoreleasePool对象时,都将调用release实例方法。 用源代码表示如下: //MRC环境下的测试: //第一步:生成并持有释放池NSAutoreleasePool对象; NSAutoreleasePool *pool = [[NSAutoreleasePool ] init]; //第二步:调用对象的autorelease实例方法; id obj = [[NSObject alloc] init]; [obj autorelease]; //第三步:废弃NSAutoreleasePool NSAutoreleasePool对象的生命周期.png 1.2 ARC下使用自动释放池 ARC环境不能使用NSAutoreleasePool类也不能调用autorelease方法,代替它们实现对象自动释放的是

    5.7K82发布于 2019-12-24
  • 来自专栏菩提树下的杨过

    objective-C中的扩展方法与partial class

    import <Foundation/Foundation.h> #import "StringUtils.h" int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString* str = @"Hello World!" import "BLL.h" #import "Product.h" #import "Order.h" int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; BLL *bll = [[BLL alloc] init]; bll.connString = @"I am

    1.1K70发布于 2018-01-22
  • 来自专栏猿人谷

    词典对象 NSDictionary与NSMutableDictionary

    #import <UIKit/UIKit.h> #import "MyClass.h" int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //添加我们的测试代码 NSDictionary *dictionary #import <UIKit/UIKit.h> #import "MyClass.h" int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //添加我们的测试代码 //创建词典对象,初始化长度为10

    1.6K70发布于 2018-01-17
  • 来自专栏技术总结

    《Objective-C高级编程》温故知新之"自动引用计数"

    autorelease 的具体使用方法如下: (1)生成并持有 NSAutoreleasePool 对象; (2)调用已分配对象的 autorelease 实例方法; (3)废弃 NSAutoreleasePool 对象 用代码来表示上图流程 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; id obj = [ **对于所有调用过 autorelease 实例方法的对象,在废弃 NSAutoreleasePool 对象时,都将调用 release 实例方法。 在大量产生 autorelease 的对象时, 只要不放弃 NSAutoreleasePool 对象,那么生成的对象就不能释放,因此有时会产生内存不足现象。eg:读入大量图像的同时改变其尺寸。 所以,需要在适当的地方生成、持有或废弃 NSAutoreleasePool 对象。

    93450发布于 2018-08-03
  • 来自专栏SpringBoot教程

    如何用 23 种编程语言说“Hello World”

    application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@"Hello, World!")

    70830编辑于 2023-03-09
  • 来自专栏linux百科小宇宙

    Ubuntu下如何安装并使用Objective-C

    然后在里面先建立一个main.m文件:   #import int main(void) {     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];        NSLog(@"Hello, world!") extern int __attribute__((fastcall)) MyASMFunc(int a, int b); int main(void) {     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];      NSLog(@"Hello, world!")

    1.2K00发布于 2021-06-17
  • 来自专栏nimomeng的自我进阶

    高级内存管理指南

    ; 避免在使用时造成deallocing: a) 当对象被移除时; b) 当指针被deallocated时 Autorelease Pools: autorelease pool 是NSAutoreleasePool 每一个线程包含自己的NSAutoreleasePool对象。当一个线程终止时,它所在的autorelease pool自动释放。

    48120发布于 2018-09-13
  • 来自专栏ShaoYL

    内存管理总结-autoreleasePool

    autoreleasepool概念 自动释放池是NSAutoreleasePool的实例,其中包含了收到autorelease消息的对象。 这里说一下,在Xcode5以前是通过NSAutoreleasePool创建实例来实现的,代码如下: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc

    1.5K60发布于 2018-05-11
  • 来自专栏菩提树下的杨过

    objective-C 的OOP(下)-类(static)方法、实例方法、overwrite(覆写)、属性(property)

    Foundation/Foundation.h> #import "Human.h" #import "Woman.h" int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // insert code here...

    96770发布于 2018-01-22
  • 来自专栏菩提树下的杨过

    objective-C中的序列化(serialize)与反序列化(deserialize)

    import <Foundation/Foundation.h> #import "Sample.h" int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Sample *s1 = [[Sample alloc] initWithName:@"thing1" magicNumber

    2.2K50发布于 2018-01-22
  • 来自专栏日常技术分享

    ios 自动释放池

    即当我们创建了一个对象,并把他加入到了自动释放池中时,他不会立即被释放,会等到一次runloop结束或者作用域超出{}或者超出[pool release]之后再被释放 自动释放池的创建与销毁时机 MRC: NSAutoreleasePool *pool = [[ NSAutoreleasePool alloc]init ];//创建一个自动释放池 Person *person = [[Person alloc]init]; //调autorelease

    2.3K32发布于 2018-09-13
  • 来自专栏移动端开发

    内存管理说明白点

    <图片数; i++) { /* 读入图片 大量产生autorelease对象 由于没有废弃NSAutoreleasepool 下面的这段伪代码有给了我们答案: for (int i=0; i<图片数; i++) { /* 在此情况下,有必要在适当的地方生成、持有或者废弃NSAutoreleasePool 对象 读入图像 大量产生autorelease对象 */ NSAutoreleasePool * pool =[[NSAutoreleasePool [pool drain]; }       那我们说了这么多,好像没有说到 @autoreleasepool ,其实在ARC有效的情况下我们就直接使用 @autoreleasepool{} 代替了NSAutoreleasePool ,但它们做的事以及其中的原理确实相同的,明白了NSAutoreleasePool也就明白了@autoreleasepool 。      

    62120发布于 2018-07-05
  • 来自专栏nimomeng的自我进阶

    《Objective C编程》笔记

    a.如果用来创建对象的方法,其方法名是以alloc或new开头的,或者包含copy,那么你已经得到了该对象的所有权(即可以假设该新对象的retain计数时1,且该对象不在NSAutoreleasePool b.通过任何其他途径创建的对象(例如便捷方法),你是没有所有权的(可以假设新对象的retain计数是1,而且该对象已经在NSAutoreleasePool对象中。 如果没有保留该对象,那么当NSAutoReleasePool对象被“排干”时,这个对象就会被释放。) autorelease会导致,当NSAutoreleasePool对象被排干时,再向相应的对象发送release消息)。

    91330发布于 2018-09-13
领券