You Are Here:

Community: Developer Discussion Boards

#1 Old device doesn't free memory - 2008-12-09, 15:38

Join Date: Sep 2008
Posts: 2
fervus
Offline
Registered User
Hello!
I am working on a J2ME game with MIDP2 and m3g.
My midlet starts more than one Thread which contains a canvase. When I exit one canvas, I stop the thread (return from it's main loop) and then I start a new Thread width a new canvas to take me to the next screen of the game. However, I noticed that the device (tested on Nokia N95) doesn't free the memory for the old thread and eventually runs out of mem.
Calling System.gc doesn't help. The wierd thing is that the emulator from SUN DOES free the memory, but not the Nokia Device:

Here is a bit of my code:

baseCanvas.exitThread();
baseCanvas=null;
baseThread=null;
System.gc();

battleCanvas = new BattleCanvas3D(this);
battleCanvas.setCommandListener(this);
battleCanvas.addCommand(exitCommand);
battleCanvas.addCommand(baseCommand);
battleThread=new Thread(battleCanvas);
battleThread.start();


where exitThread() contains:
exit=true;
and the run() method of BattleCanvas contains:
do {
if (exit) {
return;
}
.....
}

So... in this example I would like to free all the memory occupied by baseThread(baseCanvas). It does so on the emulator from SUN but not on the Nokia implementation.

Can you help me solve this problem?
Am I doing something wrong?
Thanks!
Reply With Quote

#2 Old Re: device doesn't free memory - 2008-12-09, 15:59

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
My first suggestions (for anyone writing a MIDP game):

Use only one Canvas. Switching between Displayable objects causes problems if you want to detect when your game is interrupted by an incoming call.

Create only one Thread. Multiple threads will make your life a nightmare.

So, create one Canvas instance and one Thread when the application starts, then keep them.

As to your memory leaks... are you dumping and re-loading 3D models? Or creating models dynamically? Series 60 implementations have problems garbage collecting 3D models, and tend to leak.

Load or create each model only once, and keep it.
Reply With Quote

#3 Old Re: device doesn't free memory - 2008-12-09, 17:05

Join Date: Sep 2008
Posts: 2
fervus
Offline
Registered User
Quote:
Originally Posted by grahamhughes View Post
My first suggestions (for anyone writing a MIDP game):

Use only one Canvas. Switching between Displayable objects causes problems if you want to detect when your game is interrupted by an incoming call.

Create only one Thread. Multiple threads will make your life a nightmare.

So, create one Canvas instance and one Thread when the application starts, then keep them.

As to your memory leaks... are you dumping and re-loading 3D models? Or creating models dynamically? Series 60 implementations have problems garbage collecting 3D models, and tend to leak.

Load or create each model only once, and keep it.
Yes, thank you!
I'll try that! The only problem is that every module fit in about 7-8 MB. If I preload all of them, I'll need about 15 MB. I was hoping to do with less.
Still, thank you for your reply.
Reply With Quote

#4 Old Re: device doesn't free memory - 2008-12-09, 17:17

Join Date: Jun 2003
Posts: 4,335
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
You might have to do with less.

Reduce the number of polygons in each model (this will increase performance too). This is a little outside my expertise, but I think there are tools that will optimize models by merging triangles into triangle-strips... this also reduces size and increases performance. Have a look around for different converters/exporters.
Reply With Quote

#5 Old Re: device doesn't free memory - 2008-12-10, 00:03

Join Date: May 2007
Posts: 347
Location: Mexico D.F
rdrincon's Avatar
rdrincon
Offline
Forum Nokia Expert
One more suggestion

Once a variable or object is no longer used, reference it to null, this will help much more than calling System.gc ;)


:Ruben
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Question. Free memory in Game Loop(J2ME) videador Mobile Java General 5 2009-08-24 07:05
Memory size limit when using User::Alloc or malloc (stdlib) on Nokia 6600 device pbtdanh General Symbian C++ 1 2005-10-30 13:29
How to free the memory gadkii Mobile Java General 3 2004-04-04 10:32
How to set the memory size of emulator to match with the actual device ? akokchai Mobile Java Tools & SDKs 2 2003-05-08 11:32

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia