iphone - Correct way to release a UIColor PatternImage -
i have few, full screen, uicolor patternimages
(in scrollviews
) in ipad app , experiencing memory problems (surprise?)
when started having memory issues, implemented lazy loading in scrollviews.
when problems continued, moved away factory methods (like [uicolor colorwithpatternimage:...]
) "alloc"ed methods (like [[uicolor alloc]initwithpatternimage:...]
), respond memory warnings releasing pages.
however, whenever release uicolor patternimages, “exc_bad_access”
error.
at first thought might caused [uiimage imagenamed:...]
pattern images, switched [[uiimage alloc]initwithcontentsoffile:...]
images, didn't help. set nszombiesenabled
, tells me problem is:
-[uicgcolor release]: message sent deallocated instance 0x187b50
with backtrace:
#0 0x35823910 in ___forwarding___ () #1 0x35823860 in __forwarding_prep_0___ () #2 0x357e53c8 in cfrelease () #3 0x357e48de in _cfautoreleasepoolpop () #4 0x3116532c in nspopautoreleasepool () #5 0x341a7508 in _wraprunloopwithautoreleasepoolhandler () #6 0x3580ac58 in __cfrunloop_is_calling_out_to_an_observer_callback_function__ () #7 0x3580aacc in __cfrunloopdoobservers () #8 0x358020ca in __cfrunlooprun () #9 0x35801c86 in cfrunlooprunspecific () #10 0x35801b8e in cfrunloopruninmode () #11 0x320c84aa in gseventrunmodal () #12 0x320c8556 in gseventrun () #13 0x341dc328 in -[uiapplication _run] () #14 0x341d9e92 in uiapplicationmain () #15 0x00002e5e in main (argc=1, argv=0x2fdff610) at...
i don't have uicgcolor
objects either, i'm thinking somehow "alloc"ed uicolors
have underlying uicgcolor
autorelease objects...? ideas/insight?
me had same problem , how optimized code.
after analysis in instruments , debugging found out colorwith pattern occupy 1.12 mb responsible library called ripl_create. each screen colorwithpattern occupy same 1.12 , have multiples oj 1.12 mb allocated. sucked app.so decided no colorwithpattern.
i guess want set image background of view. suggest keep imageview , place image it...
now coming imageview optimization
if want image used in many part of app or view contains image visited go imagenamed.
imagenamed cache image , not release if nil or release it.
on other case wwant image released
in viewwillappear or viewdidload assign image imageview
nsstring *filelocation = [[nsbundle mainbundle] pathforresource:@"yourimage" oftype:@"png"]; imageview.image = [uiimage imagewithdata:[nsdata datawithcontentsoffile:filelocation]];
inyour viewdiddisappear set nil release image
imageview.image=nil;
Comments
Post a Comment