Experimentos · A Lovely Computer · Capítulo 9
El cerrojo y su contador
Conteo de referencias en Objective-C: fugas y caídas
Tema
PruébeloEl cerrojo y su contador
Todo se calcula en tu navegador; no se envía nada.
Sobre este experimento
Antes de 2011, quien escribía en Objective-C para Mac o iPhone llevaba de cabeza la cuenta de los dueños. Un release olvidado dejaba el objeto en memoria para siempre, uno de más destruía un objeto todavía en uso.
El código empieza como el archivo del autor: un cerrojo creado en una variable local y nunca entregado. Recorra una apertura paso a paso mirando el contador, o abra el programa cien veces. Con ARC el compilador reparte los mensajes, pero no puede saber que usted quería entregar el cerrojo al dispositivo.
Del libro
A Lovely Computer · Capítulo 9
retain/release
It worked only at the second attempt. At the developers’ conference in June 2011, three months after my lock, they showed ARC, automatic reference counting. The rules of ownership stayed as they were, but the retain and release calls were now placed by the compiler, which reads the program and, unlike a human being, does not lose count. On the fifteenth of June Chris Lattner told a mailing list that the code of this machinery had been made public, and Xcode 4.2 acquired a menu item that converted an existing project to the new order.
My project did not live to see that menu item. I last touched it in July 2011, and the lock in it is leaking to this day.El libro se muestra en inglés