Pregunta

Cuando se crea un CGLayer como tal, y luego obtener el contexto ... que parece ser imposible liberar el CGContextRef

La liberación de la propia CGLayerRef (aparentemente) funciona bien.

Uno pensaría que podría liberar el CGContextRef justo antes de soltar el CGLayer - pero que no? Tampoco se puede liberar el CGContextRef justo después de soltar el CGLayer.

Si suelta el CGContextRef, la aplicación se bloquea.

CGLayerRef aether = CGLayerCreateWithContext(
    UIGraphicsGetCurrentContext(), CGSizeMake(1024,768), NULL);
CGContextRef weird = CGLayerGetContext(aether);

// paths, strokes, filling etc
// paths, strokes, filling etc

// try releasing weird here
CGLayerRelease(aether);
// or, try releasing weird here

¿Alguien sabe lo que está pasando aquí? (Nota además que CGContextRelease es de hecho lo mismo que CFRelease, con algunas comprobaciones nula.)

De hecho nunca se debe liberar manualmente CGContextRef? ¿Alguien sabe? Saludos.

CGContextRelease(weird); // impossible, not necessary, doesn't work???

En cuanto a la respuesta espectacular de Joel a continuación:

es la liberación de la CGLayerRef correcta y adecuada? Joel tiene salida directa:
"Sí, ya que la función que está obteniendo desde ha 'Crear' en su firma. Véase: documentación / CoreFoundation /"

¿Fue útil?

Solución

no poseen el contexto de regresar de CGLayerGetContext, y por lo tanto no debe liberarlo *. En particular, véase http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/writerid/cfGetRule para obtener información sobre ' Obtener' funciones en la Fundación Core.

*: por lo menos, no debe liberarlo dada su código de ejemplo. Si lo retuvo primero (CGContextRetain (raro)), entonces usted debe tener un CGContextRelease para equilibrarlo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top