【OC语法快览】四、基础内存管理

简介: Basic Memory Management                                                           基础内存管理 If you're writing an application for Mac OS X, you have the option to enable garbage collection.

Basic Memory Management                                                       

   基础内存管理

If you're writing an application for Mac OS X, you have the option to enable garbage collection. In general, this means that you don't have to think about memory management until you get to more complex cases. 
如果你正在写运行在Mac OS X上的程序,你可以选择开启垃圾回收功能。除非你遇到更复杂的情况,这样你就不用考虑内存管理了。

However, you may not always be working with an environment that supports garbage collection. In that case, you need to know a few basic concepts. 
但是,你的工作环境不一定都支持垃圾回收。这种情况下,你需要知道一些基本内存管理的概念。

If you create an object using the manual alloc style, you need to releasethe object later. You should not manually release an autoreleased object because your application will crash if you do. 
如果使用人工alloc方式创建实例对象,稍后需要释放掉它。不应该人工释放一个可以自动释放的对象,否则将导致程序奔溃。

Here are two examples:
这有两个例子: 

// string1 will be released automatically
NSString* string1 = [NSString string];

// must release this when done
NSString* string2 = [[NSString alloc] init];
[string2 release];



For this tutorial, you can assume that an automatic object will go away at the end of the current function. 
在这份材料中,你可以假设,一个自动释放的实例对象将会在当前函数结束后自动消失。

There's more to learn about memory management, but it will make more sense after we look at a few more concepts.
还有很多需要学习的内存管理知识,但是在我们掌握更多概念之后,学习起来更有效果。






原文:learn_objective_C part 4

相关文章
|
存储 算法 iOS开发
|
存储 安全 编译器
OC底层知识(十二) : 内存管理
OC底层知识(十二) : 内存管理
171 0
OC底层知识(十二) : 内存管理
|
存储 iOS开发 C++
OC 底层知识(一):OC的本质
OC 底层知识(一):OC的本质
208 0
OC 底层知识(一):OC的本质
|
存储 JSON 算法
Swift 与 OC 枚举的异同
Swift 与 OC 枚举的异同
Swift 与 OC 枚举的异同
|
算法 Linux
第八章--内存管理
        整个系统的性能取决于如何有效地管理动态内存。因此,现在所有多任务操作系统都在尽力优化对动态内存的使用,也就是说,尽可能做到当需要时分配,不需要时释放。 一、页框管理         Linux采用4KB页框大小作为标准的内存分配单元。
992 0
|
数据安全/隐私保护 iOS开发

热门文章

最新文章