wxWidgets: wxRefCounter Class Reference

| Version: 3.1.7

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
wxRefCounter Class Reference
Class List by Category » Runtime Type Information (RTTI)

`#include </cygdrive/c/Users/Hamis/Cygwin-packaging/wxWidgets3.1/wxWidgets3.1-3.1.7-1.x86_64/src/wxWidgets-3.1.7/interface/wx/object.h>`

Inheritance diagram for wxRefCounter:
[legend]

## Detailed Description

This class is used to manage reference-counting providing a simple interface and a counter.

wxRefCounter can be easily used together with wxObjectDataPtr<T> to ensure that no calls to wxRefCounter::DecRef() are missed - thus avoiding memory leaks.

wxObjectRefData is a typedef to wxRefCounter and is used as the built-in reference counted storage for wxObject-derived classes.

##

Library: wxBase
Category: Runtime Type Information (RTTI)

See also
  wxObject, wxObjectRefData, wxObjectDataPtr<T>, Reference Counting

## Public Member Functions
| wxRefCounter ()
| Default constructor.
void | DecRef ()
| Decrements the reference count associated with this shared data and, if it reaches zero, destroys this instance of wxRefCounter releasing its memory.
int | GetRefCount () const
| Returns the reference count associated with this shared data.
void | IncRef ()
| Increments the reference count associated with this shared data.

## Protected Member Functions
virtual | ~wxRefCounter ()
| Destructor.

## Constructor & Destructor Documentation

## ◆ ~wxRefCounter()

virtual wxRefCounter::~wxRefCounter | ( |  | ) |
| protectedvirtual

Destructor.

It's declared `protected` so that wxRefCounter instances will never be destroyed directly but only as result of a DecRef() call.

## ◆ wxRefCounter()

wxRefCounter::wxRefCounter | ( |  | ) |

Default constructor.

Initialises the internal reference count to 1.

## Member Function Documentation

## ◆ DecRef()

void wxRefCounter::DecRef | ( |  | ) |

Decrements the reference count associated with this shared data and, if it reaches zero, destroys this instance of wxRefCounter releasing its memory.

Please note that after calling this function, the caller should absolutely avoid to use the pointer to this instance since it may not be valid anymore.

## ◆ GetRefCount()

int wxRefCounter::GetRefCount | ( |  | ) | const

Returns the reference count associated with this shared data.

When this goes to zero during a DecRef() call, the object will auto-free itself.

## ◆ IncRef()

void wxRefCounter::IncRef | ( |  | ) |

Increments the reference count associated with this shared data.