4
\$\begingroup\$

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?

\$\endgroup\$
4
  • \$\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, 2015 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, 2015 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\$ Dec 9, 2015 at 19:17
  • \$\begingroup\$ Task Manager isn't really the best tool for this job. \$\endgroup\$
    – user1430
    Dec 9, 2015 at 19:19

1 Answer 1

3
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .