Discussion for Tutorial 2 - Image Class

Discussions for all the iPhone Screencast Tutorials.

Re: Discussion for Tutorial 2 - Image Class

Postby mike » Tue Nov 24, 2009 10:02 pm

Nice :)
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 2 - Image Class

Postby danegraphics » Sun Apr 11, 2010 5:24 am

I've found a not-so-major to major leak in the "getSubImageAtPoint" method. I've created an app that requires this method almost every frame and unless used so the leak is unnoticeable. The Leak Performance Tool traces it back to the first line:

Code: Select all
subImage = [[Image alloc] initWithTexture:texture scale:subImageScale];


It's clear that the allocated Image is never released and It's needs released after every frame without causing other problems (crashing, losing images in frame, etc.). How could that be done?
danegraphics
 
Posts: 2
Joined: Sun Apr 11, 2010 5:16 am

Re: Discussion for Tutorial 2 - Image Class

Postby mike » Sun Apr 11, 2010 10:57 am

I spotted some of these leaks when re-writing the methods for SLQ so the code in the book has been updated.

Fot this, I would set the returned image to autorelease e.g.
Code: Select all
return [subImage autorelease];

This will mean that where you are calling the method will have to do a retain on the returned subimage and then a release when its finished with it.

Let me know how you get on.

Cheers

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 2 - Image Class

Postby danegraphics » Sun Apr 11, 2010 10:27 pm

Thanks that worked. No more Image leak. Thanks.
danegraphics
 
Posts: 2
Joined: Sun Apr 11, 2010 5:16 am

Re: Discussion for Tutorial 2 - Image Class

Postby Thorsten » Thu Apr 15, 2010 8:32 pm

Hello Mike.

I have a memory problem with some of the classes I use from your tutorials. Instruments shows me, that I leak memory, when adding and removing images or spritesheets within my view. In these cases the methods from your classes are being called - i.e. getSpriteAtX:y:

I have the trackback from instruments here:

6 ColorRun -[SpriteSheet getSpriteAtX:y:] /Users/myUser/programming/colorrun_3.26/SpriteSheet.m:114
5 ColorRun -[Image getSubImageAtPoint:subImageWidth:subImageHeight:scale:] /Users/myUser/programming/colorrun_3.26/Image.m:183
4 CoreFoundation +[NSObject alloc]
3 CoreFoundation +[NSObject allocWithZone:]
2 libobjc.A.dylib _internal_class_createInstance
1 libobjc.A.dylib _internal_class_createInstanceFromZone
0 libSystem.B.dylib calloc


I'm pretty sure, that this is where the memory is leaked, but I do not know, whether the error is with me or in one of the classes I use from you. Within my code I allocate memory for new spritesheets and deallocate it again.

I was wondering whether you have any advice on how to approach this, since I have been trying to debug this without any success.

Thanks in advance!
Thorsten.
Thorsten
 
Posts: 1
Joined: Thu Apr 15, 2010 7:42 pm

Cocos2d vs. ImageClass

Postby mikewolf » Sat Oct 02, 2010 7:45 am

hi, there

the tutorial is very good. I like it, it is very helpful for me, as a new bee of iPhone game developer.

I have a question, should I write myself such class, e.g. Image Class and SpriteSheet Class and use them develop a game, or should I use cocos2d as game engine? In other words, those Tutorials are just for learning and for eventual understanding of the iPhone Game develop, then if man really want to develop a game, the cocos2d is a easy way?

Thanks again for the great job.
mikewolf
 
Posts: 1
Joined: Sat Oct 02, 2010 7:28 am

Re: Cocos2d vs. ImageClass

Postby A Person » Sat Oct 02, 2010 8:53 pm

mikewolf wrote:hi, there

the tutorial is very good. I like it, it is very helpful for me, as a new bee of iPhone game developer.

I have a question, should I write myself such class, e.g. Image Class and SpriteSheet Class and use them develop a game, or should I use cocos2d as game engine? In other words, those Tutorials are just for learning and for eventual understanding of the iPhone Game develop, then if man really want to develop a game, the cocos2d is a easy way?

Thanks again for the great job.


Well its really up to you, one thing that's nice about cocos2d is that everything is all setup working and ready to go with lots of features. However i find it hard to understand code that i haven't written even if its documented so that means if i need to do something special or change something i have a hard time. Besides you probably won't even use all the features cocos2d has, so for me i find that making my own engine with what i need it to do is the best way, i can change anything i want and i perfectly understand everything. If you don't find cocos2d hard to use and want to start creating iphone games right away and fast, then go with cocos2d. ;)
there's no place like ~/
A Person
 
Posts: 161
Joined: Fri Sep 25, 2009 3:45 am
Location: Canada

Previous

Return to iPhone Game Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron