XNA Content pipeline caching?

Started by
2 comments, last by Brain 12 years, 9 months ago
I was working on a game I have in the midsts and I noticed that there is a slight memory leak when I am hitting the replay button. So on a mission to fix this I found the problem, I forgot to call dispose on a texture before recreating it. Than things got interesting, even though I was specifically stating Content.Load<Texture2D>(sameTexture_as_disposed"); when I tried to assign its Name property a value it claims it is already disposed. Well, no, the old copy of this texture was disposed, now I am trying to reload it and assign the new texture a name.

Has anyone else noticed this and/or found documentation on the Content pipeline caching? I am not sure how to fix this problem other than to re-write the way the whole replay functionality works. In other API's I was able to just dispose of textures (within objects...same case here) and than reload them from the file system and viloa, no resource leaks, no false disposes.

Any insight into the caching would be great.
Thanks.

P.S. I was also thinking it could be because the GC isn't collecting the resource and that is why it is getting mixed up but I cannot see this being the case.

Remember to mark someones post as helpful if you found it so.

Journal:

http://www.gamedev.net/blog/908-xxchesters-blog/

Portfolio:

http://www.BrandonMcCulligh.ca

Company:

www.gwnp.ca

Advertisement
The content manager loads files once and hands the reference to everything else that tries to load the same file.

Do not call Dispose on anything loaded through the content pipeline: it's not your responsibility. Instead, dispose the content manager in question and it will properly unload the resources.

When it comes to a point where you want to be able to unload individual resources, start using multiple content managers. Then when you want to unload resources, dispose of the specific content manager and it will properly dispose of its contents.
Thanks a lot Flimflam that is exactly what I thought was happening.

Remember to mark someones post as helpful if you found it so.

Journal:

http://www.gamedev.net/blog/908-xxchesters-blog/

Portfolio:

http://www.BrandonMcCulligh.ca

Company:

www.gwnp.ca

XNA also caches custom content types, just to make you aware. I wasn't aware of this when i first attempted it, and found that when i modified certain parts of my object, it would alter the cached version too and not even a reload would read the original data. To fix this, i had to make a deep copy of the object (a level definition) and work on the copy.

just to let you know... :-)

This topic is closed to new replies.

Advertisement