saving array of images with UIImagePNGRepresentation memory warning swift -
i'm capturing randomly-sized/shaped sections of uiview , saving disk using uiimagepngrepresentation. files save expected, when run on device, dreaded "received memory warning", though i'm doing saving files in loop , not displaying them:
uigraphicsbeginimagecontextwithoptions(bbox.size, false, 0) cgcontextsetfillcolorwithcolor(uigraphicsgetcurrentcontext(), uicolor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.25).cgcolor) cgcontextaddrect(uigraphicsgetcurrentcontext(), cgrectmake(0, 0, bbox.width, bbox.height)) cgcontextfillpath(uigraphicsgetcurrentcontext()) let strokeimage = uigraphicsgetimagefromcurrentimagecontext() let strokefile = "stroke_\(strokebezierarraymemory.count).png" let datapng = uiimagepngrepresentation(strokeimage) let fileurl = folderurl!.urlbyappendingpathcomponent(strokefile) //println("\(fileurl)") if (datapng.writetourl(fileurl, options: .atomicwrite, error: &error) ) { //println ("wrote \(fileurl)") } else { print (error) }
i've seen similar posts, no answers solve problem. this post suggests using avfoundation, i'm hoping can stick uiimagepngrepresentation.
i tried wrapping nsdata part of code in autoreleasepool closure no avail:
autoreleasepool({ () -> () in let strokefile = "stroke_\(strokebezierarraymemory.count).png" let data = uiimagepngrepresentation(strokeimage) let fileurl = folderurl!.urlbyappendingpathcomponent(strokefile) //println("\(fileurl)") if (data.writetourl(fileurl, options: .atomicwrite, error: &error) ) { //println ("wrote \(fileurl)") } else { print (error) } })
is there way force nsdata release each datapng once written disk?
Comments
Post a Comment