Skip to content

Commit

Permalink
Update prog-dx-with-com.md
Browse files Browse the repository at this point in the history
Updated with some lifetime notes for D3D10+
  • Loading branch information
walbourn authored Jan 20, 2021
1 parent 1a97e0e commit 7b4ef75
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions desktop-src/prog-dx-with-com.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7b4ef75

Please sign in to comment.