Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Memory Leaks  (Read 3362 times)

0 Members and 1 Guest are viewing this topic.

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Memory Leaks
« on: December 12, 2008, 03:40:03 AM »

What is some advice from the pros to avoid memory leaks?  I know this can be a serious problem.  :)  I think it might be of interest generally.
« Last Edit: December 12, 2008, 03:45:00 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Jihar

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 21
    • View Profile
    • CreativeDream Studio
Re: Memory Leaks
« Reply #1 on: December 12, 2008, 09:54:42 AM »

What is some advice from the pros to avoid memory leaks?  I know this can be a serious problem.  :)  I think it might be of interest generally.
Memory leaks is a very serios problem in any software product, and games and their engines not an exception. Developer must always remember this :)
The most heavy resources in our games (and wich you can control) - actors\their animation and sounds\speeches\music. We have big quantity of actor animations, thats why we have standart set of animations for every actor (walk\talk etc), and we are using MergeAnims on start scene to load unique animations for this scene. And UnloadAnims on change scene if its a global actor. If its a local actor (was loaded using Scene object), than you have no need to unload them, WME will do it for you.
In WMEngine theres some ways to control game memory, and it highly correlates with game optimization. For example, you can decide how to allocate some actors. Will it belongs to Game or Scene? If to Game, than you can load actor once for location, wich can consist of ten scenes (for example), reducing scene loading time. And if an actor allocating by Scene object, it means you will load actor for every scene, but actor will free his memory automatically on changing scene. In case of Game object you must to do it manual. So its some kind of balance between the need of manual control by allocation\deallocation and improvements in faster loading, more flexible memory consumption controling, and game performance.
But, big thanks to WME, you can move all responsibility to engine and dont think about memory at all. You'll only need to load every entity by Scene, and it will give you garanty of memory leak absence in your game.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Memory Leaks
« Reply #2 on: December 12, 2008, 01:41:16 PM »

A perfect example of memory leak is putting

global win = Game.LoadWindow("some window"); into base.inc file.

As the script is included to almost every singles script file, you make yourself a huge mess.

Another example is dynamic object allocation

global obj = new Object("some object");

again by placing it into base.inc you make your life needlesly hard.

Rule of a thumb - game based objects, entities or windows are needed to handle manually to prevent memory leaks.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Memory Leaks
« Reply #3 on: December 13, 2008, 02:52:47 PM »

So to sum it up once more, if you use any of the Game.LoadXXX(), Game.CreateXXX() methods, you're responsible for deleting the created objects when you no longer need them.

If you use Scene.LoadXXX(), Scene.CreateXXX(), those will be deleted automatically when you leave the scene.

meta already said that, but I cannot stress it enough: never, ever, ever, ever put Game.LoadWindow() to base.inc file.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.056 seconds with 25 queries.