Re: Memory leak when re-alloc Methods
Re: Memory leak when re-alloc Methods
- Subject: Re: Memory leak when re-alloc Methods
- From: "Jonathan del Strother" <email@hidden>
- Date: Wed, 16 Apr 2008 09:00:49 +0100
On Wed, Apr 16, 2008 at 1:17 AM, Mario Gajardo Tassara
<email@hidden> wrote:
>
> El 15-04-2008, a las 14:21, email@hidden escribió:
>
>
> >
> > > I have a nasty leak problem when i realloc several methods of the main
> class of my app.
> > >
> >
> > Without seeing your code, all I can suggest is making sure you've
> > followed these rules:
> >
> >
> http://devworld.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html#
> >
> > --
> > I.S.
> >
>
> Problem solved !!! ,
>
> I just moved the alloc and init of "blisterModelClass_" from:
>
> //the button to star the game and initialize several related methods
>
> - (IBAction)button {
>
> /* blisterModelClass_=[[BlisterModel alloc]init]; */ // here
> was the leak problem
>
> [blisterModelClass_ cleanMiscArrays];
> [blisterModelClass_ initArrays];
> [blisterModelClass_ initObjectsArrays];
> [blisterModelClass_ initSpriteArrays];
> [blisterModelClass_ setObjectsMainData];
> [blisterModelClass_
> initSpritesObjectsPosition:the_cg_rect_];
> [blisterModelClass_ changeCursor];
>
> [NSTimer scheduledTimerWithTimeInterval:0.04
>
> target:self
>
> selector:@selector(refreshDisplay)
>
> userInfo:nil
>
> repeats:YES];
>
> blisterModelClass_ changeCursor];
> }
> }
>
> to the NSView initWithFrameMethod:
>
> -(id)initWithFrame:(NSRect)frameRect {
>
> self=[super initWithFrame:frameRect];
>
> if (self) {
> blisterModelClass_=[[BlisterModel alloc]init]; //
> is_full_screen_=FALSE;
> is_anim_started_=FALSE;
> }
> return self;
> }
>
> this prevent the re allocation of the same Class instance every time i hit
> the button to renew the state of the game.
>
If you've still got that timer in the button method, you're going to
be installing new timers every time the button is hit...
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden