# How to properly shut down HTML5 game instance without leaking memory?

**URL:** <https://forums.unrealengine.com/t/how-to-properly-shut-down-html5-game-instance-without-leaking-memory/329400>\
**Category:** Platform & Builds\
**Tags:** leak, HTML5, unreal-engine, memory, question, CPP\
**Created:** [August 20, 2015, 8:56pm UTC](https://forums.unrealengine.com/t/how-to-properly-shut-down-html5-game-instance-without-leaking-memory/329400 "2015-08-20T20:56:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_807ed13e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_807ed13e](https://forums.unrealengine.com/u/anonymous_user_807ed13e)\
**Post date:** [August 20, 2015, 8:56pm UTC](https://forums.unrealengine.com/t/how-to-properly-shut-down-html5-game-instance-without-leaking-memory/329400/1 "2015-08-20T20:56:18Z")

</div>

What is the best way to shut down a packaged HTML5 game without leaking memory from UE4/Emscripten/DOM? Other than just exiting / leaving the current page, of course.

[Game.html.template has a Quit button commented out, which calls \_\_exit(0).](https://github.com/EpicGames/UnrealEngine/blob/8a80b5541f69a79abf5855668f39e1d643717600/Engine/Build/HTML5/Game.html.template#L89) This seems to have no effect when un-commented.

Other things I’ve tried:

- Calling Module.exit() on the JS side reports that exit() is undefined.
- Calling Module.abort() freezes the execution, but throws a console error message/alert, and doesn’t seem to free memory.
- Binding an extern C function inside UE4 which calls emscripten\_cancel\_main\_loop. This successfully interrupts the game without error messages, but leaks all memory (i.e. nothing seems to be freed).

If anybody has any other ideas, your help would be greatly appreciated! 🙂

EDIT: Calling the “quit” console command from C++ doesn’t work either. Nor does setting the global GIsRequestingExit variable to “true.”

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_807ed13e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_807ed13e](https://forums.unrealengine.com/u/anonymous_user_807ed13e)\
**Post date:** [September 21, 2015, 10:12pm UTC](https://forums.unrealengine.com/t/how-to-properly-shut-down-html5-game-instance-without-leaking-memory/329400/2 "2015-09-21T22:12:11Z")

</div>

Still haven’t solved this question. Anybody else have any insight?
