   Does IDirect3DDevice9::SetTexture() affect reference counters?
  I've just been reading the article 2D in Direct3D using Textured Quads and towards the end it says that IDirect3DDevice9::SetStreamSource() affects the reference counters on vertex buffer objects passed to it and so to avoid a memory leak you should call IDirect3DDevice9::SetStreamSource(0, 0, 0, 0) before releasing your vertex buffers. I looked in the documentation and it doesn't seem to say this anywhere!Does IDirect3DDevice9::SetTexture() have a similar behaviour with IDirect3DTexture9 objects? i.e. does it affect the reference counters?Thanks!   
  Yes. But the reference count for any bound texture (or vertex stream, index data, etc) is decreased when the device is destroyed, or another resource takes it's place.E.g.Texture1 refcount: 1Texture2 refcount: 1* Call SetTexture(Texture1) - RC1 = 2, RC2 = 1* Call SetTexture(NULL) - RC1 = 1, RC2 = 1* Call SetTexture(Texture1) - RC1 = 2, RC2 = 1* Call SetTexture(Texture2) - RC1 = 1, RC2 = 2* Release the device - RC1 = 1, RC2 = 1* Release texture 1 - RC1 = 0 (destroyed), RC2 = 1* Release texture 2 - RC1 = 0 (destroyed), RC2 = 0 (destroyed)   ;  So in that case, would everything be released fine in this scenario..?Create DeviceCreate TextureCreate Vertex BufferDevice::SetStreamSource(..*the vertex buffer*..)Device::SetTexture(..*the texture*..)Release Vertex BufferRelease TextureRelease Device;Quote:Original post by InsaneBoarder234So in that case, would everything be released fine in this scenario..?Create DeviceCreate TextureCreate Vertex BufferDevice::SetStreamSource(..*the vertex buffer*..)Device::SetTexture(..*the texture*..)Release Vertex BufferRelease TextureRelease DeviceYup, that looks fine to me.I've not had any reason to try it, but the following should be legal:LPDIRECT3DTEXTURE9 pTex = NULL;D3DXCreateTextureFromFileEx( ... &pTex .. );Device->SetTexture( 0, pTex );SAFE_RELEASE( pTex );Device->DrawPrimitive( ... );That is, as far as your application is concerned the pTex is destroyed and only the API holds onto a reference of it - for use in the final draw call.hthJack   ;  Makes sence, thanks for helping me to clear that up!   