gerenciamento de memória em swift - the weak, the strong, and the unowned
TRANSCRIPT
Txai Wieser
• Estudante de engenharia de computação na UFRGS.
• Desenvolvedor iOS
BallphyFityItWarrenRecolorindo o ReinoRepel
heap
ObjectAlloc
vmmap
MallocScribble
free
malloc
release
retainautoreleasepool
MANUAL
destroy
Gerenciador de Memória
Programador
alloccopy
autoreleaseAUTOMÁTICO
assign
__autoreleasing
__unsafe_unretained
Gerenciador de Memória
heap
ObjectAlloc
vmmap
MallocScribble
free
malloc
release
retainautoreleasepool
MANUAL
destroy
Programador
alloccopy
autoreleaseAUTOMÁTICO
assign
__autoreleasing
__unsafe_unretained
Programador Garbage Collector
AUTOMÁTICOMANUAL
Gerenciador de Memória
(+)determinístico
(-)trabalhoso
(+)automático
(-)afeta o runtime
Programador Garbage Collector
AUTOMÁTICO
Compilador
MANUAL
Gerenciador de Memória
ARC
(+)determinístico
(-)trabalhoso
(+)automático
(-)afeta o runtime
ARC Garbage Collector
Tracing garbage collection is a form of automatic memory management that consists of determining which objects should be deallocated by tracing which objects are reachable by a chain of references f r o m c e r t a i n “ r o o t ” objects, and considering the rest as “garbage” and collecting them.
Reference counting is a technique of storing the number of references, pointers, or handles to a resource such as an object, block of memory, disk space or other resource. It may a l s o r e f e r , m o r e specifically, to a garbage collection algorithm that uses these reference counts to deallocate objects which are no longer referenced.
Prevenção
• Relações de Posse
• NSTimer
Cuidado Use logs:
-(void)dealloc {
NSLog(@"object is being deallocated"); }
deinit { println("object is being deallocated") }
• Closures
• Referencias para classes
• UIAlertController
⚠
Referências:
• https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html
• http://www.ibm.com/developerworks/library/mo-ios-memory/