iphone - UIScrollView PhotoViewer receives memory warning after 125 photos on iPod -
i stuck in weird problem,tried find out solution possible sources no luck yet.
my requirement similar photoviewer app of iphone,but there more uploading image,downloading etc .so technically doing creating main scrollview,which has content size equal selected image size * image width .i have little view within equal no. of images selected picker .the view contains little scrollview,and image view allows user zoom,pinch etc , main scroll view has gesture listner allows swipe. access images storing asset url , image when user swipes left or right .at point in time keeping 1 image memory i.e if user swipe 2nd photo delete 1st photo main scrollview .
but still facing memory issues on ipod if selected 125 photos , swipe multiple times end , come .
sample code.:-
***//innerscrollview class contains view scroll , imageview //the values of initial , final counter diffrence of 1 creates 1 object** for(int j=initialcounter;j<finalcounter;j++) { innerscrollview *innerscrollviewobj=[[innerscrollview alloc] initwithframe:cgrectmake(320*j, 0, 320, 480) url:[selectedimagelist objectatindex:j] tag:self.initialimageviewcounter]; innerscrollviewobj.delegate=self; [mainscrollview addsubview:innerscrollviewobj]; [innerscrollviewobj release]; innerscrollviewobj=nil; } **//this main scrollview gets created once** mainscrollview = [[uiscrollview alloc] initwithframe:cgrectmake(0,0 , 320, 480)]; mainscrollview.pagingenabled = yes; // mainscrollview.delegate=self; mainscrollview.showshorizontalscrollindicator = no; mainscrollview.showsverticalscrollindicator = no; mainscrollview.maximumzoomscale = 4.0; mainscrollview.minimumzoomscale = 1.0; mainscrollview.backgroundcolor=[uicolor blackcolor]; [mainscrollview setcancancelcontenttouches:no]; mainscrollview.clipstobounds = yes; mainscrollview.scrollenabled = false; mainscrollview.contentsize = cgsizemake(320*[selectedimagelist count], mainscrollview.bounds.size.height); [self.view addsubview:mainscrollview]; //this method gets called when swipe left , previous images gets deleted -(void)deletescrollviewformmainview:(nsnumber*)indextodelete{ @try{ nslog(@"scrollview deleted %@",[[mainscrollview subviews] objectatindex:0]); [[[mainscrollview subviews] objectatindex:0] removefromsuperview]; } @catch (nsexception *e) { nslog(@"scrollview view exception %@",[e description]); } } - (id)initwithframe:(cgrect)frame url :(alasset*) imageurl tag:(int)tag { self = [super initwithframe:frame]; if (self) { self.userinteractionenabled=yes; // self.tag=tag; uiimage *image = [uiimage imagewithcgimage:[[imageurl defaultrepresentation] fullresolutionimage ]]; uiimageview* imageview = [[uiimageview alloc] initwithimage:image]; imageview.tag = view_for_zoom_tag; imageview.frame=cgrectmake(0, 0, self.frame.size.width, self.frame.size.height); imageview.backgroundcolor=[uicolor clearcolor]; imageview.contentmode=uiviewcontentmodescaleaspectfit; uiscrollview* pagescrollview = [[uiscrollview alloc] initwithframe:cgrectmake(0, 0, self.frame.size.width, self.frame.size.height)]; nslog(@"page scrollview %@",pagescrollview); pagescrollview.tag=tag; pagescrollview.minimumzoomscale = 0.4f; pagescrollview.maximumzoomscale = 2.0f; pagescrollview.zoomscale = 1.0f; pagescrollview.backgroundcolor=[uicolor clearcolor]; pagescrollview.delegate = self; pagescrollview.showshorizontalscrollindicator = no; pagescrollview.showsverticalscrollindicator = no; [pagescrollview setcancancelcontenttouches:no]; [self addsubview:pagescrollview]; [pagescrollview addsubview:imageview]; uitapgesturerecognizer *singletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handlesingletap)]; singletap.numberoftapsrequired=1; singletap.delegate=self; [self addgesturerecognizer:singletap]; singletap=nil; uitapgesturerecognizer *doubletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handledoubletap)]; doubletap.numberoftapsrequired=2; doubletap.delegate=self; [self addgesturerecognizer:doubletap]; singletap=nil; doubletap=nil; imageview=nil; pagescrollview=nil; } homecoming self; }
should create innerimageview class singelton class?will help,because think memory issues can because multiple objects getting created(though release properly).
please help guys.!! in advance.
can post definition of innerscrollview
? problem delegate
property retain
, keeping innerscrollviewobj beingness deallocated.
so, assume have like:
@property (nonatomic, retain) id delegate;
which should be:
@property (nonatomic) id delegate;
or, if enable arc should be:
@property (nonatomic, weak) id delegate;
also, maintain in mind [mainscrollview subviews]
holds views, not controllers. if deallocate controller not able respond events or command anything, , may errors due sending messages deallocated objects.
iphone objective-c uiscrollview memory-warning photoviewer
No comments:
Post a Comment