Summary of Manual Memory Management Rules
来源:互联网 发布:电信端口扩容10天解决 编辑:程序博客网 时间:2024/05/18 03:23
Here are some rules to remember when working with a project compiled without ARCor garbage collection:
- If you need to hold onto an object to make sure it doesn’t get destroyed by some-one else, you shouldretainit. Make sure to release the object when you’re done with it.
- Sending a release message does not necessarily destroy an object.When an object’s reference count is decremented to 0, the object is destroyed.The system does this by sending the dealloc message to the object to free its memory.
- Release any objects that you have retained or have created using a copy,mutableCopy,alloc, ornew method.This includes properties that have theretain or copy attribute.You can override dealloc to release your instance variables at the time your object is to be destroyed.
- The autorelease pool provides for the automatic release of objects when the pool itself is drained.The system does this by sending a release message to each object in the pool for each time it was autoreleased. Each object in the autorelease pool whose reference count goes down to 0 is sent a dealloc message to destroy the object.
- If you no longer need an object from within a method but need to return it, send it an autorelease message to mark it for later release.The autorelease message does not affect the reference count of the object.
- When your application terminates, all the memory your objects take up is released,regardless of whether they were in the autorelease pool.
- When you develop Cocoa or iOS applications, autorelease pools will be created and drained throughout execution of the program (this will happen each time an event occurs). In such cases, if you want to ensure that an autoreleased object survives automatic deallocation when the autorelease pool is drained, you need to retain it.All objects that have a reference count greater than the number of autorelease messages they have been sent will survive the release of the pool.
From:<Programming in Objective-C 4th Edition>
- Summary of Manual Memory Management Rules
- Manual Memory Management
- Ownership of Memory Management
- Memory Management of primary
- The summary of virtual memory
- Simple summary of virtual memory
- C中内存分配及管理小结 中英文对照 (Summary of C memory allocation and management Chinese&Englise)
- Memory Management of Global Variables
- Components of Summary Management【物化视图】
- Memory Management of Instance Variables (Non-ARC)
- Memory Management of Instance Variables (ARC)
- The effective memory management of C++
- An overview of memory management in QEMU
- k2 workflow rules summary
- OOM killer "Out of Memory: Killed process" SOLUTIONS / SUMMARY
- OOM killer "Out of Memory: Killed process" SOLUTIONS / SUMMARY
- Memory Management
- Memory Management
- c++宏编程一览
- vc++与MySQL数据库的连接(windows)
- auto_ptr
- RAC Failover三种方式
- string类的简单实现
- Summary of Manual Memory Management Rules
- GetMem(myString,1024);//开辟1024个字节FreeMem(myString,1024);//释放
- Action中设置和读取作用域属性
- 乔布斯的13句经典妙语
- Data model in python
- 搜索无向图中两点之间的所有路径(java)
- hdu1559
- Fedora 启动 SSH服务
- Thoughts on TypeScript by Nicholas C. Zakas