Click here to Skip to main content
13,354,605 members (64,756 online)
Rate this:
Please Sign up or sign in to vote.

I am very new to XNA framework. I am writing a sample application in XNA for windows phone 7.

presently I am facing a problem.

In the sample, I am loading a Texture2D and disposing it in the next line and then assigning it to null. Again I am loading the same image to the same member variable. But in the draw I get ObjectDisposedException.

If I remove the dispose call it will not give any exception.

Please help me to solve this.

Texture2D texture = null;
 protected override void LoadContent()
      texture = Content.Load<Texture2D>("Back");
      texture .Dispose();
      texture = null;

      texture = Content.Load<Texture2D>("Back");
protected override void Draw(GameTime gameTime)

      spriteBatch.Draw(texture , new Vector2(0, 0), Color.White);


Posted 20-Jul-10 3:30am
Updated 20-Jul-10 3:39am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I would assume then that Content.Load is caching off the textures.

To verify this:

1) Put a breakpoint right before you dispose it.
2) Apply an object ID to the object in the watch panel.
3) On the line after you load "Back" again, see if its the same object ID.

Something along those lines should clear that up...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 20 Jul 2010
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100