Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Dov Sherman

Avoiding Memory Leaks

This topic is 5601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the DirectX 8 documentation for SetStreamSource, it says: "When the vertex buffer is no longer needed, set it to NULL. If you fail to do this, the vertex buffer is not released, resulting in a memory leak." But I''m not sure what "set it to NULL" means. Does it mean that I should do this... pDirect3DDevice->SetStreamSource(0, pVertexBuffer, sizeof(ALPHATEX_VERTEX)); ...after rendering or that I need to do... pVertexBuffer->Release(); pVertexBuffer = NULL; ...when I want to destroy the buffer later?

Share this post


Link to post
Share on other sites
Advertisement
What it means is that if you are done using the VB as a stream source *and* you don''t have another VB to take its place, you should:

pDirect3DDevice->SetStreamSource(0, NULL, 0);

The reason is that SSS increments the ref count when you set a new VB as a stream source. If there was a previous VB, its ref count is decremented. So if you are simply setting a new VB as stream source 0, just call:

pDirect3DDevice->SetStreamSource(..., pNewVertexBuffer, ...);

and all is well.

If you didn''t set the stream source to NULL, you''d probably get some debug spew on exit about unreleased memory, but in most cases there''s no real harm in this.

Either way, when you are done with the vertex buffer, yes, you should call Release on it.

In DX9, SetStreamSource apparently does not bump the ref count (I just did a little experiment to test this), and the docs say somewhat cryptically "When an application no longer holds a references to this interface, the interface will automatically be freed." So apparently in 9 it''s not as important to set the stream source to NULL.

Still I''d be inclined to set it to NULL anyway, just out of paranoia.

Share this post


Link to post
Share on other sites
I see! Is the same thing true for SetTexture()? Can I safely SetTexture() to different textures consecutively and only SetTexture(0, NULL) when I''m done rendering textured polys?

Share this post


Link to post
Share on other sites
quote:
Original post by Dov Sherman
I see! Is the same thing true for SetTexture()? Can I safely SetTexture() to different textures consecutively and only SetTexture(0, NULL) when I''m done rendering textured polys?


If you don''t do that you''ll get all your polys textured...


KaMiKaZe

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!