Partager via


COM Reference Count Semantics for Surfaces (Windows Embedded CE 6.0)

1/6/2010

Being built upon COM means that DirectDraw follows certain rules that employ reference counts to manage object lifetimes. For a conceptual overview, see the COM documentation; a DirectDraw-centered discussion of the topic is found in Parent and Child Object Lifetimes.

By COM rules, when an interface pointer is copied by setting it to another variable or passing to another object, that copy represents another reference to the object, and therefore the IUnknown::AddRef method of the interface must be called to reflect the change.

Not only should you follow COM reference counting rules when working with DirectDraw objects, but you should become familiar with the situations in which DirectDraw internally updates reference counts.

Some DirectDraw methods — mostly those involving complex surface flipping chains — affect the reference counts of the surfaces involved, while methods involving clippers or palettes affect the reference counts of those objects.

Knowing about these situations can make the difference in your application's stability and can prevent memory leaks.

For more information, see Parent and Child Object Lifetimes in Working with DirectDraw Objects.

See Also

Concepts

Working with DirectDraw Surfaces