VM: CG raster Data memory continues to grow

so I'm trying to create an application that will allow the user to change the color of the UIImage because I use this function that I found

 - (UIImage *)imageWithTintColor:(UIColor *)color fraction:(CGFloat)fraction
{
    if (color)
    {
        UIImage *image;
        if ([UIScreen instancesRespondToSelector:@selector(scale)])
        {
            UIGraphicsBeginImageContextWithOptions([self size], NO, 0.f);
        }
        else
       {
           UIGraphicsBeginImageContext([self size]);
       }

       CGRect rect = CGRectZero;
       rect.size = [self size];
       [color set];
       UIRectFill(rect);

       [self drawInRect:rect blendMode:kCGBlendModeDestinationIn alpha:1.0];

       if (fraction > 0.0)
       {
           [self drawInRect:rect blendMode:kCGBlendModeSourceAtop alpha:fraction];
       }
       image = UIGraphicsGetImageFromCurrentImageContext();
       UIGraphicsEndImageContext();
       return image;
   }
   return self;
}

everything works, but CG raster data grows in memory enter image description here

+4
source share
2 answers

I found a problem, and that was my bad logic, I use 2 views to show and one to work with ex: resize, move, rotate. And every time I added Subview for both, where one of them needs to hold only 1 at a time, it's simple:

  for (UIView *view in 2cndView.subviews)
  {
    [view removeFromSuperview];
  }

did the trick for me

0
source

, , . , , Render as Template , . CG Raster Data , , , Xcode

iPhone.. ..

, "", . , - .

0

Source: https://habr.com/ru/post/1568960/


All Articles