My game uses a lot of images, for the over-world, battle screens, chats, etc. I'm really meticulous when it comes to memory management, and I've noticed that even though I dispose every image when I load in a new one, the memory never goes down.

Isn't this what Dispose() should do or is my understanding wrong?

  • \$\begingroup\$ "I dispose every image when I load in a new one" -- Possibly because you are loading a new image when you dispose, therefore, using memory up again making it look like it didn't dispose? \$\endgroup\$
    – jgallant
    Dec 9 '15 at 19:04
  • \$\begingroup\$ Also, depending on how you're profiling your memory usage, you could be looking at the wrong values or misinterpreting the data. \$\endgroup\$
    – user1430
    Dec 9 '15 at 19:09
  • \$\begingroup\$ @Jon I mean it still increases, not stays the same. Also I use my Task Manager to check the memory usage. \$\endgroup\$
    – GigaNova
    Dec 9 '15 at 19:17
  • \$\begingroup\$ Task Manager isn't really the best tool for this job. \$\endgroup\$
    – user1430
    Dec 9 '15 at 19:19

Disposal patterns like LibGDX's in languages with GCs often have to do with releasing un-managed resources in addition to (or instead of) managed memory. This true with C#'s IDisposable interface, and based on the documentation LibGDX's pattern serves a similar purpose.

This means that simply looking at private working-set CPU-side RAM use may not be an accurate way to tell if disposing of the resource is "working as intended" or not. For example, if a texture isn't caching its image data on the CPU (expecting it to be on the GPU), then disposing it will not impact CPU-side memory appreciably at all.

LibGDX's source code is on GitHub, so you can take a look at the specific implementations of the dispose method. For example, texture's or pixmap's.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.