From 7b4ef75a00561ba19f42a8cbab28702eaf4c8483 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 19 Jan 2021 21:34:34 -0800 Subject: [PATCH] Update prog-dx-with-com.md Updated with some lifetime notes for D3D10+ --- desktop-src/prog-dx-with-com.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/desktop-src/prog-dx-with-com.md b/desktop-src/prog-dx-with-com.md index ccf46eba361..6abb7fde4d7 100644 --- a/desktop-src/prog-dx-with-com.md +++ b/desktop-src/prog-dx-with-com.md @@ -226,6 +226,9 @@ An object's reference count is the number of times one of its interfaces has bee Properly handling reference counting is a crucial part of COM programming. Failure to do so can easily create a memory leak or a crash. One of the most common mistakes that COM programmers make is failing to release an interface. When this happens, the reference count never reaches zero, and the object remains in memory indefinitely. +> [!NOTE] +> Direct3D 10 or later has slightly modified lifetime rules for objects. In particular, objects that are derived from **ID3DxxDeviceChild** never outlive their parent device (i.e. if the owning **ID3DxxDevice** hits a 0 refcount, all child objects are immediately invalid as well). Also, when you use ``Set`` methods to bind objects to the render pipeline, these references do not increase the reference count (i.e. they are weak references). In practice, this is best handled by ensuring you release all device child objects fully before you release the device. + ## Incrementing and decrementing the reference count Whenever you obtain a new interface pointer, the reference count must be incremented by a call to [**IUnknown::AddRef**](/windows/desktop/api/unknwn/nf-unknwn-iunknown-addref). However, your application doesn't usually need to call this method. If you obtain an interface pointer by calling an object creation method, or by calling **IUnknown::QueryInterface**, then the object automatically increments the reference count. However, if you create an interface pointer in some other way, such as copying an existing pointer, then you must explicitly call **IUnknown::AddRef**. Otherwise, when you release the original interface pointer, the object may be destroyed even though you may still need to use the copy of the pointer.