---
name: "sc_RefCount"
section: "3"
platform: "linux"
package: "libsc-doc"
version: "2.3.1-22"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/sc_RefCount"
---

# sc\_RefCount(3)

The base class for all reference counted objects.

## NAME

sc::RefCount - The base class for all reference counted objects.

## SYNOPSIS

`#include <ref.h>`

Inherits **sc::Identity**.

Inherited by **sc::CorrelationTable**, **sc::DescribedClass**, **sc::DipoleData**, **sc::Edge**, **sc::EfieldDotVectorData**, **sc::FJT**, **sc::GenPetite4**, **sc::Int1eCCA**, **sc::Int1eCints**, **sc::Int1eV3**, **sc::Int2eCCA**, **sc::Int2eCints**, **sc::Int2eV3**, **sc::KeyVal**, **sc::KeyValValue**, **sc::MOPairIter**, **sc::NonlinearTransform**, **sc::OneBodyDerivInt**, **sc::OneBodyInt**, **sc::OneBodyIntIter**, **sc::OneBodyOneCenterDerivInt**, **sc::OneBodyOneCenterInt**, **sc::OneBodySOInt**, **sc::PetiteList**, **sc::PointChargeData**, **sc::PrimPairsCints**, **sc::PsiFile11**, **sc::PsiInput**, **sc::R12Amplitudes**, **sc::SCMatrixSubblockIter**, **sc::SOBasis**, **sc::ShellExtent**, **sc::ThreadLock**, **sc::TriInterpCoef**, **sc::Triangle**, **sc::TwoBodyDerivInt**, **sc::TwoBodyInt**, **sc::TwoBodySOInt**, **sc::TwoBodyThreeCenterDerivInt**, **sc::TwoBodyThreeCenterInt**, **sc::TwoBodyTwoCenterDerivInt**, **sc::TwoBodyTwoCenterInt**, **sc::Vertex**, and **sc::X**.

### Public Member Functions

int **lock\_ptr** () const\
 Lock this object.  int **unlock\_ptr** () const\
 Unlock this object.  void **use\_locks** (bool inVal)\
 start and stop using locks on this object  refcount\_t **nreference** () const\
 Return the reference count.  refcount\_t **reference** ()\
 Increment the reference count and return the new count.  refcount\_t **dereference** ()\
 Decrement the reference count and return the new count.  int **managed** () const\
 void **unmanage** ()\
 Turn off the reference counting mechanism for this object.  int **managed** () const\
 Return 1 if the object is managed. Otherwise return 0.

### Protected Member Functions

**RefCount** (const **RefCount** &)\
 **RefCount** & **operator=** (const **RefCount** &)\

## Detailed Description

The base class for all reference counted objects.

If multiple inheritance is used, **RefCount** must be virtually inherited from, otherwise references to invalid memory will likely result.

Reference counting information is usually maintained by smart pointer classes **Ref**, however this mechanism can be supplemented or replaced by directly using the public interface to **RefCount**.

The **unmanage()** member is only needed for special cases where memory management must be turned off. For example, if a reference counted object is created on the stack, memory management mechanisms based on reference counting must be prohibited from deleting it. The **unmanage()** member accomplishes this, but a better solution would be to allocate the object on the heap with new and let a smart pointer manage the memory for the object.

When using a debugger to look at reference counted objects the count is maintained in the *reference\_count* member. However, this member is encoded so that memory overwrites can be sometimes detected. Thus, interpretation of *reference\_count* is not always straightforward.

## Member Function Documentation

### void sc::RefCount::unmanage ()` [inline]`

Turn off the reference counting mechanism for this object. The value returned by **nreference()** will always be 1 after this is called. The ability to **unmanage()** objects must be turned on at compile time by defining REF\_MANAGE. There is a slight performance penalty.

## Author

Generated automatically by Doxygen for MPQC from the source code.
