tailieunhanh - HandBooks Professional Java-C-Scrip-SQL part 119
Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 119', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Don t call -copy instead of -retain in a setter. It is safe as far as memory usage goes but prevents your caller from sharing the value by contrast when you use -retain a caller can copy the new object explicitly and pass the copy to the setter. Deallocating an object When a call to -release sets your object s reference count to zero the -release method will also call the object s -dealloc method. In that method you should release all other objects . fields and resources that your object is retaining. If other code that shares those objects is retaining them as it should this will be safe. You can make your -dealloc method safer in the face of outside code that may have bugs by calling -autorelease on your retained objects. This leaves the autoreleased objects still available until the current call stack finishes. However it is probably a design mistake if code remaining in the call stack depends on these objects and using -autorelease may just hide this rather than solve it. Retain cycles Reference counting can break down when there is a closed loop in the graph of object references. In this case a group of mutually referent objects may be garbage . unreachable from your program but with positive reference counts. You don t have to avoid such structures but make sure that you only apply the counting in one direction. When two objects refer to each other decide which is the owner and let it retain the other object but not vice versa. Garbage Collection Garbage collection is a memory management technique that fully automates the release and reuse of object memory. A garbage collector keeps track of which objects are reachable from running code unreachable objects those with no references direct or indirect are released. The gcc compiler emits code that can be linked with the Boehm garbage collector an open source garbage collector for C-based languages . This library augments the standard C function malloc with code that sets up .
đang nạp các trang xem trước