Posts Tagged ‘java’


Memory leak and Android / Java

posted by Karsten

in Uncategorized

Many (novice) programmers think that managed environments, such as Java, is memory leak free. The Garbage collector (GC) will just take care of all memory management, and everyone will be happy! Over the last few days I’d have wished this was the case…

The reason this isn’t true is that if something is referencing the object which is not in use, the GC can’t clean it up, and you can potentially end up with a mountain of wasted memory. Last Friday I suddenly realised that I might have been a bad boy and created one of these situations within my game. I could only play 10-15 games in a row on my machine and then it would crash with a heap allocation error. This is typically what will happen in this situation.

Obviously I thought that I’d been cleaning up within my code, but something was a miss. It took me many hours to fix this one, and I believe it is worthwhile mentioning this one, as it is a problem others are likely to get caught in!

The situation:

  • To minimise memory usage bitmaps are referenced statically within classes
  • One of these are used as background within a view set using setBackgroundDrawable(Drawable d)

What happens here is that a callback is create from the static bitmap to the view, so when the view object is nullified or goes “out of sight” there still exist a callback from the static bitmap to the view (even if is within a class not in use). Therefore the GC cannot cleanup the view object, and through that the context is reference, which means pretty much everything you’ve created within your view. For me that meant 4 full background images, and on a phone that means a lot of memory…

Therefore, this callback needs to be cleaned up manually!


Android game – Meet BoB

posted by Karsten

in Uncategorized

I’ve now got the first start to my first game using the engine. Ok, granted if you’ve seen my test game it doesn’t look like much has happened, and actually there hasn’t. Today’s work has mostly evolved around testing different screen sizes, SDKs and changing the layout of menus, while messing with my Linux box and Windows 7 box.

But anyway, I feel like it is a good time to show this preliminary view of the game. So, for your eyes only:



Android Game Progression

posted by Karsten

in Uncategorized

Bob gameSince sometime last autumn, I decided that the time I used to spend on my PhD work in the evenings, was badly substituted with TV. I therefore started working on a Android game platform, mostly to keep learning new skills, and enjoy coding something different from the normal work code.

I’ve now managed to get to a stage where the goals for my game engine is closing to an end. The engine is a simplistic world, where boxes, balls and holes of different sizes, colours and attributes can be instantiated, and rules can be made between them. The biggest problem I have faced was making the engine smooth, or indeed, as smooth as a Garbage Collected environment, like Java, can become. I figured out that having different parts of the game in different threads from the system thread is a must, and I managed to minimize garbage collection 7 times by optimizing the use of internal objects. So now, the “stutter” that is in the system comes primarily from outside sources. The only thing I need now is to finish the persistency system behind the engine and I’ll be going into “real” game making territory.

I’ve already started on a Bob / couronne type of game, which I have set up as a debugging platform in the engine building stage.