Swift Codice
Quando arriviamo uno screenshot di un'UIView, usiamo questo codice di solito:rapida UIGraphicsGetImageFromCurrentImageContext non può liberare la memoria
UIGraphicsBeginImageContextWithOptions(frame.size, false, scale)
drawViewHierarchyInRect(bounds, afterScreenUpdates: true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Problema
drawViewHierarchyInRect
& & UIGraphicsGetImageFromCurrentImageContext
genererà un immagine nel contesto corrente, ma la memoria sarà non rilasciata quando è chiamata UIGraphicsEndImageContext
.
La memoria continua ad aumentare fino a quando l'app si arresta in modo anomalo.
Anche se c'è una parola UIGraphicsEndImageContext
chiamerà CGContextRelease
automaticamente", non funziona.
Come posso rilasciare la memoria drawViewHierarchyInRect
o UIGraphicsGetImageFromCurrentImageContext
utilizzato
Or?
C'è qualche cosa che genera screenshot senza drawViewHierarchyInRect
?
Già provato
1 Rilascio automatico: non funzionare
var image:UIImage?
autoreleasepool{
UIGraphicsBeginImageContextWithOptions(frame.size, false, scale)
drawViewHierarchyInRect(bounds, afterScreenUpdates: true)
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
image = nil
2 UnsafeMutablePointer: non funziona
var image:UnsafeMutablePointer<UIImage> = UnsafeMutablePointer.alloc(1)
autoreleasepool{
UIGraphicsBeginImageContextWithOptions(frame.size, false, scale)
drawViewHierarchyInRect(bounds, afterScreenUpdates: true)
image.initialize(UIGraphicsGetImageFromCurrentImageContext())
UIGraphicsEndImageContext()
}
image.destroy()
image.delloc(1)
Vedo che hai nessuna risposta dopo 2 mesi, e penso che sto ottenendo lo stesso problema. Non penso che tu abbia trovato una soluzione o una soluzione alternativa? – Martin
Ho riscontrato lo stesso problema e ho cercato una soluzione. – Hope