xcode - Too many open files iOS -


i new on ios programming, when app running , taking these errors. loading 950+ images in app , using arc.

imageio: cgimageread_mapdata 'open' failed '/users/apple/library/application support/iphone simulator/6.1/applications/16551664-4694-4742-85dc-2c3c0adc5289/demo.app/menu-24-20.png'error = 24 (too many open files)

imageio: cgimageread_mapdata 'open' failed '/users/apple/library/application support/iphone simulator/6.1/applications/16551664-4694-4742-85dc-2c3c0adc5289/demo.app/menu-24-20.png'error = 24 (too many open files)

imageio: cgimageread_mapdata 'open' failed '/users/apple/library/application support/iphone simulator/6.1/applications/16551664-4694-4742-85dc-2c3c0adc5289/demo.app/circle_green.png' error = 24 (too many open files)

imageio: cgimageread_mapdata 'open' failed '/users/apple/library/application support/iphone simulator/6.1/applications/16551664-4694-4742-85dc-2c3c0adc5289/demo.app/circle_green.png' error = 24 (too many open files)

imageio: cgimageread_mapdata 'open' failed '/users/apple/library/application support/iphone simulator/6.1/applications/16551664-4694-4742-85dc-2c3c0adc5289/demo.app/shopping_cart_1-512.png' error = 24 (too many open files)

imageio: cgimageread_mapdata 'open' failed '/users/apple/library/application support/iphone simulator/6.1/applications/16551664-4694-4742-85dc-2c3c0adc5289/demo.app/shopping_cart_1-512.png' error = 24 (too many open files)

this code block part of app.

                while(sqlite3_step(compiledstatement) == sqlite_row)  {                     int urunid = sqlite3_column_int(compiledstatement,0);                     //nsstring *urunno= [nsstring stringwithformat:@"%i",urunid];                     urunadi = [nsstring stringwithutf8string:(char*)sqlite3_column_text(compiledstatement, 1)];                     nsstring *imagename= [nsstring stringwithutf8string:(char*)sqlite3_column_text(compiledstatement, 2)];                     uiimageview *background = [[uiimageview alloc]initwithframe:cgrectmake(column*197+30, row*350, 175, 280)];                      nsstring *filepathbackground = [[nsbundle mainbundle] pathforresource:@"backimage" oftype:@"png"];                     nsdata *mydata = [nsdata datawithcontentsoffile:filepathbackground];                                             uiimage *blackbackground = [uiimage imagewithdata:mydata];                      [background setimage:blackbackground];                                                                 [scrollview addsubview:background];                        nsstring *filepathsepeteeklebutton = [[nsbundle mainbundle] pathforresource:@"sepeteeklebuttonimage" oftype:@"png"];                     nsdata *mydatabutton = [nsdata datawithcontentsoffile:filepathsepeteeklebutton];                      uiimage *sepeteeklebuttonimage = [uiimage imagewithdata:mydatabutton];                     uibutton * button = [uibutton buttonwithtype:uibuttontypecustom];                     [button setframe:cgrectmake(column*197+38 , row*350+8, 159, 45)];                     [button setimage:sepeteeklebuttonimage forstate:uicontrolstatenormal];                     [button addtarget:self                                action:@selector(addtochart:)                      forcontrolevents:uicontroleventtouchupinside];                     button.tag = urunid;                        uilabel *buttonlabel=[[uilabel alloc]initwithframe:cgrectmake(column*197+43,row*350+20,200,20)];                     buttonlabel.textcolor = [uicolor whitecolor];                     buttonlabel.backgroundcolor=[uicolor clearcolor];                     buttonlabel.text=urunadi;                      [scrollview addsubview:button];                      [scrollview addsubview:buttonlabel];                       nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);                     nsstring *documentspath = [paths objectatindex:0]; //get docs directory                     nsstring *filepath = [documentspath stringbyappendingpathcomponent:imagename];                      nsdata *pngdata = [nsdata datawithcontentsoffile:filepath];                     if (pngdata == nil) {                         nsstring *filepathresimyok= [[nsbundle mainbundle] pathforresource:@"resimyok" oftype:@"jpeg"];                         nsdata *mydataresimyok= [nsdata datawithcontentsoffile:filepathresimyok];                         image2 = [uiimage imagewithdata:mydataresimyok];//horoda                     }else{                         image2 = [uiimage imagewithdata:pngdata];                     }                     image2=[image2 imagebyscalingandcroppingforsize:cgsizemake(175, 210)];                      //uiimage *urundetayimage = [uiimage imagenamed:image2];                     uibutton * urundetaybutton = [uibutton buttonwithtype:uibuttontypecustom];                     [urundetaybutton setframe:cgrectmake(column*197+38 , row*350+58, 159, 170)];                     [urundetaybutton setimage:image2 forstate:uicontrolstatenormal];                     [urundetaybutton addtarget:self                                         action:@selector(buttonclicked:)                               forcontrolevents:uicontroleventtouchupinside];                     urundetaybutton.tag = urunid;                     [scrollview addsubview:urundetaybutton];                      uilabel *label=[[uilabel alloc]initwithframe:cgrectmake(column*197+38,row*350+245,200,20)];                     label.textcolor = [uicolor whitecolor];                     label.backgroundcolor=[uicolor clearcolor];                     label.text=urunadi;                     [scrollview addsubview:label]; 

i trying fix 3 days.please me. thanks.

as far can see code looks fine, , running in simulator (where plenty of memory) should working. few suggestions:

1) use datawithcontentsoffile:options:error: instead of datawithcontentsoffile:, use nsdatareadinguncached option (to reduce memory pressure on system), , test return value - if nil log error , update question.

2) can dump data image in nscache object, , if system needs memory release cache items, , you'll have re-read image file system. can use technique if pull few images @ time.

3) can use uiimage imagewithcontentsoffile: instead of getting data creating image. in case put uiimage in cache, key of name.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -