ios - GPUImage memory accumulation filtering images into UITableViewCell's UIImageView -
i have listed bunch of gpuimage filters uitableview 1 filter per uitableviewcell. using uitableviewcell's uiimageview image show sample of image may filter.
however, when pop view lists filters, memory not cleared. when open women again, accumulates more memory doesn't deallocated. hangup that's not deallocated memory?
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsuinteger index = [indexpath row]; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"filtercell"]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"filtercell"]; cell.textlabel.textcolor = [uicolor blackcolor]; } cell.accessorytype = uitableviewcellaccessorydisclosureindicator; switch( index ) { case gpuimage_saturation: cell.textlabel.text = @"saturation"; break; case gpuimage_contrast: cell.textlabel.text = @"contrast"; break; case gpuimage_brightness: cell.textlabel.text = @"brightness"; break; case gpuimage_levels: cell.textlabel.text = @"levels"; break; case gpuimage_exposure: cell.textlabel.text = @"exposure"; break; case gpuimage_rgb: cell.textlabel.text = @"rgb"; break; case gpuimage_hue: cell.textlabel.text = @"hue"; break; case gpuimage_whitebalance: cell.textlabel.text = @"white balance"; break; case gpuimage_monochrome: cell.textlabel.text = @"monochrome"; break; /* more omitted */ } nsstring *identifier = [nsstring stringwithformat:@"%lu", (unsigned long)index]; uiimage *image = imagecache[ identifier ]; if( image ) [[cell imageview] setimage:image]; else { // placeholder image [[cell imageview] setimage:[uiimage imagenamed:@"placeholder.png"]]; // if( mytableview.dragging == no && mytableview.decelerating == no) // { dispatch_async(dispatch_get_main_queue(), ^{ uiimage *image = [self filterpreview:index]; if( !image ) return; imagecache[ identifier ] = image; // make sure cell still available nsindexpath *myindexpath = [mytableview indexpathforcell:cell]; if( myindexpath==nil || myindexpath.row==indexpath.row ) { [[cell imageview] setimage:image]; [mytableview beginupdates]; [mytableview reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationnone]; [mytableview endupdates]; } }); // } } return( cell ); } and function call:
- (uiimage *)filterpreview:(gpuimageshowcasefiltertype)filtertype { gpuimageoutput<gpuimageinput> *filter; switch( filtertype ) { case gpuimage_sepia: { filter = [[gpuimagesepiafilter alloc] init]; }; break; case gpuimage_pixellate: { filter = [[gpuimagepixellatefilter alloc] init]; }; break; case gpuimage_polarpixellate: { filter = [[gpuimagepolarpixellatefilter alloc] init]; }; break; case gpuimage_pixellate_position: { filter = [[gpuimagepixellatepositionfilter alloc] init]; }; break; case gpuimage_polkadot: { filter = [[gpuimagepolkadotfilter alloc] init]; }; break; case gpuimage_halftone: { filter = [[gpuimagehalftonefilter alloc] init]; }; break; case gpuimage_crosshatch: { filter = [[gpuimagecrosshatchfilter alloc] init]; }; break; case gpuimage_colorinvert: { filter = [[gpuimagecolorinvertfilter alloc] init]; }; break; case gpuimage_grayscale: { filter = [[gpuimagegrayscalefilter alloc] init]; }; break; case gpuimage_monochrome: { filter = [[gpuimagemonochromefilter alloc] init]; [(gpuimagemonochromefilter *)filter setcolor:(gpuvector4){0.0f, 0.0f, 1.0f, 1.f}]; }; break; /* more of same omitted */ } uiimage *returnimage = [filter imagebyfilteringimage:sampleimage]; return( returnimage ); }
Comments
Post a Comment