sken3r.MI sken3r.MI - 1 year ago 237
iOS Question

VM: CG raster Data memory keep growing

so i am trying to make an app that will let the user change the color of the UIImage, for that i am using this function i found

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

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

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

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

everything works but the CG raster Data is growing in memoryenter image description here

Answer Source

I found the problem, and it was my bad logic, i am using 2 views one to show and one to work with ex:resize, move, rotate. And each time i was addingSubview to both where one of them need to hold just 1 at a time, a simple:

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

did the trick for me

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download