Skip to main content
gamedev.net
🔒 Locked

Weird Memory Problem

Started by RelisH Dec 2, 2001 at 9:54 AM 4 replies 150+ views
Original Post
RelisH
RelisH
I''ve been getting an error stating that I have unfreed memory, but the thing is that I know that I have released all of my textures, vertex buffers etc. The number of bytes that were left still allocated were around 760k, which told me that it must be a texture. the bizarre thing is that I believe that I have found where the problem resides, but not how to solve it. What I did was set a texture I was using to null (and not load it) and then the number of allocated bytes dropped to roughly 230K. I know that I am releasing the Texture at the end because the line''s there in the Destructor of the class that holds my textures. I''m sure I didn''t accidently set the texture pointer to 0 because I stepped through and it did indeed release the texture. Because of this, it seems that the leak exists in the g_pDevice->SetTexture(0, sometexture) or somewhere around there because when I commented out the code for the object that uses the texture, the number of allocated bytes went to around 230K again. Are there any special properties about SetTexture?
-RelisH!
Daniel Smertnig
Daniel Smertnig
Are you setting the Texture to NULL at the end? (g_pDevice->SetTexture(0, 0)).
You need to do the same for your Vertex-Buffers & Index-Buffers, because DirectX calls AddRef() for these resources.
This is out of the docs for SetTexture():

Remarks
This method increments the reference count of the texture surface being assigned and decrements the reference count of the previously selected texture if there is one. When the texture is no longer needed, set the texture at the appropriate stage to NULL. Failure to do this results in a memory leak.
RelisH
RelisH
Excellent, I''ve shaved off most off most of the allocated memory, but I still have 231k allocated. I''ve double checked how I was handling my vertex buffers and index buffers and made sure I wasn''t re-creating either without first releasing but I havent found any problems. What else could be causing the leak? I''m sure it''s not the textures now because I tried disabling (or not loading) the textures and there was no change and also I''ve made sure that I settexture(0,0) after Im done using every texture.
-RelisH!
RelisH
RelisH
Hmm, I read the notes on SetStreamSource, and it says to do the same, and set it to null when Im done with it, so Im assuming that''s SetStreamSource(0,0,0) (assuming no need to supply size and FVF) which didn''t seem to help my memor problem
-RelisH!
Daniel Smertnig
Daniel Smertnig
Did you do the same for your Index Buffers?
If you''re using the DX 8.1 SDK you might want to go to the DX Control Panel and enter the allocation ID of the unfreed block into the field "Break On AllocID" (The ID should be included in the mem-leak message).
NightShade
NightShade
Daniel, that is a great idea, I''m glad I checked this thread again, it might come in handy in the future!
-ns-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.