objective c - GPUImage memory usage -
i noticed more use gpuimage, more memory app takes on time (using instruments monitor memory use).
as example, use each filter in different methods:
 (uiimage*)toonfilter:(uiimage*)theimage     {     gpuimagesmoothtoonfilter *smoothtoonfilter = [[gpuimagesmoothtoonfilter alloc] init];     [smoothtoonfilter settexelheight:0.0025];     [smoothtoonfilter settexelwidth:0.0025];     return [smoothtoonfilter imagebyfilteringimage:theimage];     }      (uiimage*)sketchfilter:(uiimage*)theimage     {     gpuimagesketchfilter *sketchfilter = [[gpuimagesketchfilter alloc] init];     [sketchfilter settexelheight:0.003];     [sketchfilter settexelwidth:0.003];     return [sketchfilter imagebyfilteringimage:theimage];     }      (uiimage*)pixellatefilter:(uiimage*)theimage     {     gpuimagepixellatefilter *pixellatefilter = [[gpuimagepixellatefilter alloc] init];     [pixellatefilter setfractionalwidthofapixel:0.01;     return [pixellatefilter imagebyfilteringimage:theimage];     } and how use these filters (testimage uiimage):
testimage = [self sketchfilter:testimage]; testimage = [self pixellatefilter:testimage]; if cycle through these filters on , over, without doing else, app takes more , more memory.
what doing wrong? how can release memory once don't need anymore?
you keep allocating new filters every time call these functions. create them once in view controller etc , send them functions sample code below (as gpuimagepicture). don't forget call [removealltargets] on filters, not removed memory when have targets
(uiimage*)pixellatefilter:(uiimage*)theimage withpixellatefilter:(gpuimagepixellatefilter *) pixellatefilter andstaticpicture:(gpuimagepicture *)staticpicture and use [filter prepareforimagecapture] before getting uiimage filters
for example can build function like
(uiimage*)pixellatefilter:(uiimage*)theimage withpixellatefilter:(gpuimagepixellatefilter *) pixellatefilter andstaticpicture:(gpuimagepicture *)staticpicture{     [staticpicture removealltargets];     uiimage __block *imagetoreturn;     [staticpicture addtarget:pixellatefilter];     [staticpicture processimagewithcompletionhandler:^{             [pixellatefilter prepareforimagecapture];             imagetoreturn = [pixellatefilter imagefromcurrentlyprocessedoutput];             [pixellatefilter removealltargets];             pixellatefilter = nil;     }];     return imagetoreturn; } i use gpuimageview application allows use gpuimagefilters , gpuimagepictures directly without getting uiimage, should consider
Comments
Post a Comment