I was wondering if loadGraphicsContent can ever be called with loadAllContent=true except the very first time. The reason it's an important issue is that if it can, references can go dead, ex. if I load effect in Game1 and give it to object X, then Game1.loadGraphicsContent(true) is called and I have to reload effect, X's reference to effect is no longer any good. This can be solved with some simple indirection, but it would be nicer not to do that if it isn't necessary.

I'm also curious if it's ever necessary to explicitly Dispose() a resource, such as a VertexBuffer, if it is created with ResourceManagementMode.Automatic, or if everything will be taken care of when it is garbage collected. Part of my concern is that I had a huge problem with MDX9 where such objects were not getting garbage collected because they had captured some device events which kept them live even after my code no longer had any direct reference to them. Is there anything like that going on here


Re: XNA Framework Resource management


If an object implements IDisposable, you should call Dispose() on it when you're finished using it whenever possible. You could leave it for the GC, but that's not really a good way to do it.

If you have object A and object B and you register A into an event in B, then that will stop A from being garbage collected as there is a valid reference to A being held alive. If you want A to be garbage collected, remember to unregister A from the event in B.

Re: XNA Framework Resource management


Ok. Does it cause any problems to dispose a ResourceManagementMode.Automatic object

Also, regarding events, what I meant was will objects like VertexBuffer do things like hook GraphicsDevice events automatically What made the MDX bug I referred to so tricky is that VertexBuffers and other objects hook Device events unless a Device flag is turned off, so this was happening in a way that was not very intuitive and not documented anywhere that I could find except in the topic for the flag itself, which I had no idea was of any relevance until I read a blog comment by Tom Miller suggesting that it should be turned off.

So, in a nutshell, if I do this:

vb=new VertexBuffer(args...,ResourceManagementMode.Automatic);

will vb be garbage collected eventually If not, then if I were to Dispose() it before nullifying the referenec, would it be garbage collected eventually

EDIT: I can't seem to get VertexBuffers garbage collected at all, as it turns out:

TestClass t=new TestClass();

VertexBuffer vb=new VertexBuffer(graphics.GraphicsDevice, 100, ResourceUsage.None, ResourceManagementMode.Manual);
//According to ANTS profiler, vb is live but t is not.

EDIT 2: The CLR Profiler shows why the VB is not being disposed: The device just has a reference to the most recently created resource. I know it's a little weird to poke around like this, I just wanted to make sure because I had big problems with it in the past :P

So, there's one question left:

Do I have to worry about loadGraphicsContent(true) being called more than once