Tuesday, 15 March 2011

iphone - CGLayerCreateWithContext CGContext leak -


Why is this leak happening?

I do not like this idea very much to ask a question which is very specific and there is the possibility of helping many other people, but for a few hours of scratching my head Afterwards, I have not left any option.

The leaking tool reports that the following code leak occurs: / P>

  - (zero) such as abscondualoffholes {UIGraphicsBeginImageContextWithOptions (CGSizeMake (50.0f, 50.0f), Yes, 0.0 F); CGContextRef Reference = UIGraphicsGetCurrentContext (); CGLayerRef * Size Layer = Malloc (3 * size (* Size Layer)); (Int i = 0; I   

Specifically, it reports that the CGLayerCreateWithContext function is a problem but this object is leaking and not the objects, which it gives:

Leaks  leak

I doubt that my problem is due to the fundamental lack of understanding of memory management / dynamic allocation and anyone should know me 'this' finger because I There is no leak in the following code Is:

  - (void) No Lex {UIGraphicsBeginImageContextWithOptions (CGSizeMake (50.0f, 50.0f), yes, 0.0f); CGContextRef Reference = UIGraphicsGetCurrentContext (); CGLayerRef Shape Layer = CGLayerCreateWithContext (Reference, CGSizeMake (5.0f, 5.0f), NULL); CGLayerRelease (shapeLayer); UIGraphicsEndImageContext (); }   

Please note that this is clearly a problem in its simple copy-deferable state. I am using dynamic memory allocation because the size of the array in my actual code is not known at compile time.

I can not tell you why the Instruments reports that CGContext Objects are leaking, and not CGLayer , but

  •   shape layer [i] = CGLear crat vethacontax (reference, CGS immec (5.0 F, 5.0F) ), Nouel);   

    Definitely should be issued with

      CGLARLIZ (size layer [ii]);   

    and not

      free (shape layer [i]);   

    is not CGLayerCreateWithContext malloc , so calling for that code free can cause memory corruption .

  • No comments:

    Post a Comment