19

I've been working on a game in for HTML 5 using the canvas tag, and I've build up quite a code base to cover my requirements. I also want to make sure I'm covering up all my memory leaks.

I have doubts I'm doing it correctly because the feedback I'm getting from Chrome's task manager and profiling tools seem to suggest my cleanup is having no effect in the end.

Here's an image so you can see what I mean:

enter image description here

So as you can see, once I do my cleanup memory usage just freezes and doesn't drop. Is this a memory leak?

When I ran my webpage in the Profiler and checked the heap before and after cleanup it does appear to remove all the references to my objects (and they disappear) but my usage only drops by only a few kilobytes leaving about 1.3mb of arrays, strings, and other objects behind. Is it impossible to catch all this or is there something majorly wrong?

Thanks.

7
  • I suspect the issue you are describing is unrelated to memory leaking, but just to be on the safe side, how do you "cleanup memory" ? Commented Apr 17, 2011 at 5:21
  • @Khez Each of my objects has a destroy function and in it they set all objects they contain to null, and any arrays they empty, any dom references are removed from their parents and set to the null, etc.' Commented Apr 17, 2011 at 19:59
  • Then I assume chrome just keeps the memory alive for later use. Commented Apr 18, 2011 at 2:33
  • I assume you're detaching all event handlers, as well? Are you still having this problem, or have you solved it? Commented Dec 29, 2011 at 13:57
  • 2
    Are you anywhere using the javascript delete keyword to remove objects? (comes with issues well outlined here: perfectionkills.com/understanding-delete) Commented Jan 5, 2012 at 16:37

3 Answers 3

3

At the bottom of the profiler window there is an icon that looks like a trash can, it will force a GC pass.

Hit it and see if it clears up the rest of the memory.

It's possible Chrome/V8 just doesn't think the memory situation is bad enough to require garbage collection to run.

Sign up to request clarification or add additional context in comments.

1 Comment

That did make it drop to around 1mb. Unfortunately there are still tons of strings and arrays lingering that I can't find.
1

Try chrome://memory-redirect/ (or about:memory, both go to the same place). It'll show you the exact amount of memory being used by each tab/etc, plus the memory used by tags/etc in IE, Opera, Firefox, etc. if you have those open at the same time. The raw numbers should be a little more helpful than just the graph at profiling your memory use for potential leaks.

1 Comment

I also have since discovered chrome://tasks/ which is a bit more real-time.
1

You can compare two heap snapshots and see the delta. You can also directly look at the memory snapshot: https://developers.google.com/chrome-developer-tools/docs/heap-profiling-comparison?hl=pt-PT

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.