How to debug a memory leak [Solved]

0 favourites
  • 6 posts
From the Asset Store
Memory game, with 10 levels for you to have fun. Made in Construct3, template available for purchase.
  • Hi,

    I've got an issue on my game where the longer it runs, the slower it gets.

    Could someone please point me to any resources on how to debug this on Construct 3?

    I'm guessing I'm not destroying something that's leaving the screen correctly but would like to find out specifically what the cause is.

    Thanks as always

    Tom

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think I'm familiar with this slowdown. It's most likely not a memory leak since RAMs are massive nowadays. Most likely a CPU processing backlog, hence drop in FPS.

    Most common case is the abuse use of Every Tick. Browsers are significantly not as efficient as native applications and even native applications don't always run scripts in every frame.

    Construct 3 makes it easy to use Every Tick so casually, but it should always be used with caution and batched in a single cycle.

    Think of it like this, if the current tick cycle didn't complete the entire process of the event sheet but still need to process that same event sheet in the next cycle, then there will be more and more backlogs overtime until the CPU significantly slows down.

    Usually in app development, you would use listeners (Triggers) to apply events and only use every tick for those that has to run every frame. In order to not waste the CPU's processing power.

    It's easy to debug CPU processing in Construct 3, you can use Construct 3's built-in Debugger - Profiler.

  • It may be caused by some objects that you are creating and not destroying, like bullets. Run the game in debug mode, play for a while and check the number of instances in the list of objects.

  • You can also lessen the amount of tick cycles.

    The Construct 3 Community made a clever tickcount % n, I wrapped it into an addon, in the C3 Addons page, click here to download.

  • Thanks for the replies!

    chadorireborn - you mentioned something I wanted to ask about:

    "it should always be used with caution and batched in a single cycle."

    I have been careful with every tick but have around 5 running concurrently.

    Generally speaking, would having one on tick event, with all actions within that one be better for performance?

    Thanks again - I've checked the number of objects using debug layout and it's also fine.

  • Quick follow up on this for anyone with this problem in the future.

    I found the cause of my gradual slow down the longer the game was running:

    Objects being created but not being destroyed when leaving the screen.

    I made several mistakes where objects (or pinned objects) weren't being destroyed when leaving the screen and being allowed to 'live on', causing degradation in performance over time.

    The main reason I'm writing this follow up is to highlight a method I used to get to the bottom of the issue and find the problem sprites.

    It's hard to debug this in most games, where you're not spawning a huge number of objects at a time. You'd need to leave your game running a long time to see where the game was slowing down.

    One good way around this is to create tests in your game where you take each object at a time, and spawn that object many times. I spawned one object every 0.01 seconds using the Every X seconds event.

    Then use debug layout and check that the objects on screen count reaches and stays at a stable level. IE as it's not going up - and objects are being destroyed just as fast as they're being created.

    If they're being destroyed properly upon leaving the screen, or the layout, the count will remain stable.

    There's several handy ways to destroy objects that leave the screen on Construct:

    - Checking their position on the layout

    - Using has left layout behaviour

    - Using the inverted 'is on screen' event

    TL;DR

    1) If your game is slowing down over time, check objects are being created and destroyed properly.

    2) Test each object separately.

    3) Create a simple test in your game to spawn HUGE numbers of each object you are testing to save testing time.

    4) Check the OBJECT COUNT in Debug layout

    Peace out!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)