How to deal with used/unused materials?

Hi guys,

OK let’s say I’m loading materials every now and then, for example when a terrain chunk appears or disappears, I want it to fade, so instead of tagging the VBO with +16000 opacity floats, I simply set a new material on it, change 1 float parameter every 10ms and voila, nice fadeIn/fadeOut effect to that chunk. Once the chunk is completely faded in, I set the material to a global/broad opaque terrain material that every other chunk already uses.

My question now is: Let’s say somebody plays for 2-3 consecutive hours… Is there a way I can do manual garbage collection on older materials? Is there like a function to list all used/usused materials or am I digging too deep for nothing here? I have wrapped the materials creation in a singleton class so that everytime I do: new Material() it’s always from within that class and so I have kept a list of all instanciated materials, but is there a way to actually know if they can be destroyed or something? If I play for 30 minutes, I get more than 1000 instanciated materials, but obviously, only 20-25 are used at once so I guess it’s not about fps optimization here but more about RAM optimization.

Thx for your advice.

The materials take almost no RAM at all. 1000 of them is nothing. Probably less than a single texture’s RAM.

Incremental GC will eventually claim them. You could force it with System.gc() but that will pause all threads for a second or two.

OK this confirms I’m just being paranoid lol

I’ll let the automatic GC collect them once every minute or so.