{"id":4215,"date":"2014-03-30T09:24:01","date_gmt":"2014-03-30T09:24:01","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-tiny-memory-leak-in-this-func-related-to-uigraphicsbeginimagecontext-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:24:01","modified_gmt":"2014-03-30T09:24:01","slug":"why-tiny-memory-leak-in-this-func-related-to-uigraphicsbeginimagecontext-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-tiny-memory-leak-in-this-func-related-to-uigraphicsbeginimagecontext-collection-of-common-programming-errors\/","title":{"rendered":"Why tiny memory leak in this func related to UIGraphicsBeginImageContext?-Collection of common programming errors"},"content":{"rendered":"<p>I have a simple function to create an UIImage with special size :<\/p>\n<pre><code>- (UIImage*)imageWithSize:(CGSize) imSize\n{\n    UIGraphicsBeginImageContext( imSize );\n\n    float r = 0.5f;\n    float g = 0.5f;\n    float b = 0.5f;\n\n    CGContextRef cxt = UIGraphicsGetCurrentContext();\n    CGContextSetRGBStrokeColor(cxt, r, g, b, 1.0);\n    CGContextSetRGBFillColor(cxt, r,g,b, 1.0);\n    CGContextFillRect(cxt, CGRectMake(0.0, 0.0, imSize.width, imSize.height));\n\n    UIImage* retImg = UIGraphicsGetImageFromCurrentImageContext();\n\n    UIGraphicsEndImageContext();\n\n    return retImg;\n}\n<\/code><\/pre>\n<p>and then I call it MANY times in this way (I&#8217;m using ARC):<\/p>\n<pre><code>for(int i=0;i<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a simple function to create an UIImage with special size : &#8211; (UIImage*)imageWithSize:(CGSize) imSize { UIGraphicsBeginImageContext( imSize ); float r = 0.5f; float g = 0.5f; float b = 0.5f; CGContextRef cxt = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(cxt, r, g, b, 1.0); CGContextSetRGBFillColor(cxt, r,g,b, 1.0); CGContextFillRect(cxt, CGRectMake(0.0, 0.0, imSize.width, imSize.height)); UIImage* retImg = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4215","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4215"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4215\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}