Loading...
Searching...
No Matches
juce::ReferenceCountedObject Class Reference

## Detailed Description

A base class which provides methods for reference-counting.

To add reference-counting to a class, derive it from this class, and use the ReferenceCountedObjectPtr class to point to it.

e.g.

class MyClass : public ReferenceCountedObject
{
void foo();
// This is a neat way of declaring a typedef for a pointer class,
// rather than typing out the full templated name each time.
using Ptr = ReferenceCountedObjectPtr<MyClass>;
};
MyClass::Ptr p = new MyClass();
MyClass::Ptr p2 = p;
p = nullptr;
p2->foo();
juce::ReferenceCountedObjectPtr
A smart-pointer class which points to a reference-counted object.
Definition juce_ReferenceCountedObject.h:259
juce::ReferenceCountedObject::ReferenceCountedObject
ReferenceCountedObject()=default
Creates the reference-counted object (with an initial ref count of zero).

Once a new ReferenceCountedObject has been assigned to a pointer, be careful not to delete the object manually.

This class uses an Atomic<int> value to hold the reference count, so the reference count can be updated on multiple threads. Note that whilst it's thread-safe to create and delete a ReferenceCountedObjectPtr to a ReferenceCountedObject shared between threads, it's not thread-safe to modify or swap the ReferenceCountedObject.

For a faster but non-thread-safe version, use SingleThreadedReferenceCountedObject instead.

See also
  ReferenceCountedObjectPtr, ReferenceCountedArray, SingleThreadedReferenceCountedObject

The documentation for this class was generated from the following file:

- juce_core/memory/juce_ReferenceCountedObject.h

Inheritance diagram for juce::ReferenceCountedObject:

## Public Member Functions

void | incReferenceCount () noexcept
| Increments the object's reference count.
void | decReferenceCount () noexcept
| Decreases the object's reference count.
bool | decReferenceCountWithoutDeleting () noexcept
| Decreases the object's reference count.
int | getReferenceCount () const noexcept
| Returns the object's current reference count.

## Protected Member Functions

| ReferenceCountedObject ()=default
| Creates the reference-counted object (with an initial ref count of zero).
| ReferenceCountedObject (const ReferenceCountedObject &) noexcept
| Copying from another object does not affect this one's reference-count.
| ReferenceCountedObject (ReferenceCountedObject &&) noexcept
| Copying from another object does not affect this one's reference-count.
ReferenceCountedObject & | operator= (const ReferenceCountedObject &) noexcept
| Copying from another object does not affect this one's reference-count.
ReferenceCountedObject & | operator= (ReferenceCountedObject &&) noexcept
| Copying from another object does not affect this one's reference-count.
virtual | ~ReferenceCountedObject ()
| Destructor.
void | resetReferenceCount () noexcept
| Resets the reference count to zero without deleting the object.

## Constructors and Destructors

## ReferenceCountedObject() [1/3]

juce::ReferenceCountedObject::ReferenceCountedObject | ( |  | ) |

protected default

Creates the reference-counted object (with an initial ref count of zero).

Referenced by operator=(), operator=(), ReferenceCountedObject(), and ReferenceCountedObject().

## ReferenceCountedObject() [2/3]

juce::ReferenceCountedObject::ReferenceCountedObject | ( | const ReferenceCountedObject & |  | ) |

inline protected noexcept

Copying from another object does not affect this one's reference-count.

References ReferenceCountedObject().

## ReferenceCountedObject() [3/3]

juce::ReferenceCountedObject::ReferenceCountedObject | ( | ReferenceCountedObject && |  | ) |

inline protected noexcept

Copying from another object does not affect this one's reference-count.

References ReferenceCountedObject().

## ~ReferenceCountedObject()

virtual juce::ReferenceCountedObject::~ReferenceCountedObject | ( |  | ) |

inline protected virtual

Destructor.

References getReferenceCount(), and jassert.

## Member Functions

## incReferenceCount()

void juce::ReferenceCountedObject::incReferenceCount | ( |  | ) |

inline noexcept

Increments the object's reference count.

This is done automatically by the smart pointer, but is public just in case it's needed for nefarious purposes.

Referenced by juce::ReferenceCountedObjectPtr< SynthesiserSound >::operator=().

## decReferenceCount()

void juce::ReferenceCountedObject::decReferenceCount | ( |  | ) |

inline noexcept

Decreases the object's reference count.

If the count gets to zero, the object will be deleted.

References getReferenceCount(), and jassert.

## decReferenceCountWithoutDeleting()

bool juce::ReferenceCountedObject::decReferenceCountWithoutDeleting | ( |  | ) |

inline noexcept

Decreases the object's reference count.

If the count gets to zero, the object will not be deleted, but this method will return true, allowing the caller to take care of deletion.

References getReferenceCount(), and jassert.

## getReferenceCount()

int juce::ReferenceCountedObject::getReferenceCount | ( |  | ) | const

inline noexcept

Returns the object's current reference count.

Referenced by decReferenceCount(), decReferenceCountWithoutDeleting(), and ~ReferenceCountedObject().

## operator=() [1/2]

ReferenceCountedObject & juce::ReferenceCountedObject::operator= | ( | const ReferenceCountedObject & |  | ) |

inline protected noexcept

Copying from another object does not affect this one's reference-count.

References ReferenceCountedObject().

## operator=() [2/2]

ReferenceCountedObject & juce::ReferenceCountedObject::operator= | ( | ReferenceCountedObject && |  | ) |

inline protected noexcept

Copying from another object does not affect this one's reference-count.

References ReferenceCountedObject().

## resetReferenceCount()

void juce::ReferenceCountedObject::resetReferenceCount | ( |  | ) |

inline protected noexcept

Resets the reference count to zero without deleting the object.

You should probably never need to use this!

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited