Oracle Coherence for C++ API
Release 3.6.1.0
E18813-01

- Main Page
- Namespaces
- Classes
- Files

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# HeapAnalyzer Class Reference

`#include <coherence/lang/HeapAnalyzer.hpp>`

Inherits Object.

Inherited by AbstractHeapAnalyzer`[virtual]`, and ObjectCountHeapAnalyzer`[virtual]`.

List of all members.

## Detailed Description

HeapAnalyzer provides a base diagnostics interface for tracking heap usage.

There is at most one HeapAnalyzer registered with the system for the lifetime of the process. The HeapAnalyzer implementation may be specified via the "tangosol.coherence.heap.analyzer" system property. The property can be set to one of the following values:

- none No heap analysis will be performed.
- object The coherence::lang::ObjectCountHeapAnalyzer will be used.
- class The coherence::lang::ClassBasedHeapAnalyzer will be used.
- alloc The coherence::lang::ClassBasedHeapAnalyzer will be used, in allocation analysis mode.
- [custom] The name of a class registered with the SystemClassLoader.

In the case where a custom class is specified, it must implement this interface. The custom analyzer will be initialized as soon as the class is registered with the SystemClassLoader. As static initialization order cannot be guaranteed, this custom analyzer will not be notified of managed objects created earlier in the static initialization order.

The active analyzer may be obtained from the System::getHeapAnalyzer() method.

The HeapAnalyzer and Snapshot interfaces are intentionally narrow. Implementations are expected to provide useful information via the toStream method, as well as by possibly augmenting the interfaces. The minimal interface is sufficient for detecting memory leaks.

HeapAnalyzer::Snapshot::View vSnap = hAnalyzer->capture(); ... ... std::cout << "Heap changed by: " << hAnalyzer->delta(vSnap) << std::endl;

See also:
  ObjectCountHeapAnalyzer

  ClassBasedHeapAnalyzer

Author:
  mf 2008.04.27

## Public Types
typedef spec::Handle | Handle
| HeapAnalyzer Handle definition.
typedef spec::View | View
| HeapAnalyzer View definition.
typedef spec::Holder | Holder
| HeapAnalyzer Holder definition.
## Public Member Functions
virtual Snapshot::View | capture () const =0
| Capture a Snapshot of the current state of the heap.
virtual Snapshot::View | delta (Snapshot::View vThat) const =0
| Compute the delta between the supplied Snapshot and the current heap state.
virtual int64_t | getObjectCount () const =0
| Return the number of registered objects.
## Static Public Member Functions
static Snapshot::View | ensureHeap (Snapshot::View vSnap=NULL, int64_t cDelta=0)
| Ensure that the delta between the current heap and the supplied snapshot is as expected.
## Protected Member Functions
virtual void | registerObject (const Object &o)=0
| Register a newly created Object with the system.
virtual void | unregisterObject (const Object &o)=0
| Unregister an Object with the system.
## Classes
class | Snapshot
| Snapshot provides a abstract mechanism for comparing successive heap analysis points. More...

## Member Function Documentation

virtual Snapshot::View capture | ( |  | ) | const`[pure virtual]`

Capture a Snapshot of the current state of the heap.

Note, when performing captures in a loop, and assigning the captured snapshot to a handle referencing a snapshot, it is advisable to NULL out the handle first, so as to avoid the new snapshot including the "cost" of snapshot it is about to replace.

Returns:
  a Snapshot of the current state of the heap.

Implemented in ClassBasedHeapAnalyzer, and ObjectCountHeapAnalyzer.

virtual Snapshot::View delta | ( | Snapshot::View | vThat | ) | const`[pure virtual]`

Compute the delta between the supplied Snapshot and the current heap state.

Parameters:

  | vThat | the snapshot to compare against.

Returns:
  a snapshot containing the delta

Implemented in ClassBasedHeapAnalyzer, and ObjectCountHeapAnalyzer.

virtual int64_t getObjectCount | ( |  | ) | const`[pure virtual]`

Return the number of registered objects.

Returns:
  the number of registered objects

Implemented in ClassBasedHeapAnalyzer, and ObjectCountHeapAnalyzer.

virtual void registerObject | ( | const Object & | o | ) | `[protected, pure virtual]`

Register a newly created Object with the system.

This method is called automatically by coherence::lang::Object once the Object has finished construction.

Parameters:

  | o | the newly created Object.

Implemented in AbstractHeapAnalyzer, ClassBasedHeapAnalyzer, and ObjectCountHeapAnalyzer.

virtual void unregisterObject | ( | const Object & | o | ) | `[protected, pure virtual]`

Unregister an Object with the system.

This method is called automatically by coherence::lang::Object just prior to the deletion of the Object. No new handles or views may be created to the object.

Parameters:

  | o | the Object to unregister

Implemented in AbstractHeapAnalyzer, ClassBasedHeapAnalyzer, and ObjectCountHeapAnalyzer.

static Snapshot::View ensureHeap | ( | Snapshot::View | vSnap = `NULL`,
|  | int64_t | cDelta = `0` |
| ) |  |  | `[static]`

Ensure that the delta between the current heap and the supplied snapshot is as expected.

This method can be used to perform quick memory leak assertions.

     HeapAnalyzer::Snapshot::View vSnapStart = HeapAnalyzer::ensureHeap();
       ...
       ...
     HeapAnalyzer::ensureHeap(vSnapStart);

Parameters:

  | vSnap | the snapshot to ensure; or NULL for return only
  | cDelta | the allowable change in the heap's object count

Returns:
  a new Snapshot

Exceptions:

  | IllegalStateException | if the delta does not contain the expected amount. The text of the exception will include the output of the Snapshots toStream() method.

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

- coherence/lang/HeapAnalyzer.hpp

Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.