2005/5/10

     
 

Memory debuging

artefaktur

| Heaps | Allocator | Memory Debuging | RC/GC mechanism |



ACDK Provides several mechanism to trace memory usage.


Content of this chapter:

   Get all allocated root objects
   Using core_memtrace to list memory allocated by allocators


 Get all allocated root objects


The class  acdk::lang::System provides a method to retrive all root objects. Root objects are Object instances, which are not hold by another Object instance.
This includes global objects, static class members and objects which are currently held as stack varialbes.

 Using core_memtrace to list memory allocated by allocators



#include <acdk/lang/sys/core_memtrace.h>
// ....
{
  ::acdk::lang::sys::core_memtrace trace;
  {
    RStringBuffer sb = new StringBuffer();
    sb->append("asdf");
    sb->lockMem(true); // force not to free StringBuffer
    
  }
  // report memory here
  trace.reportUnfreed();
}
This reports (here as sample under Windows) following report with 3 pointer are not freed. StringBuffer*, String* and byte buffer held by String
  pointer: 0x15da4ac; size=68; type=2;
allocated at:
  C:\d\artefaktur\acdk\acdk_core\src\acdk\lang\Object.cpp(106):
      acdk::lang::ObjectBase::operator new
  C:\d\artefaktur\acdk\acdk_core\tests\acdk\lang\acdk_lang_String2_Test.cpp(232):
      tests::acdk::lang::String2_Test::memuse
  ../../../../include\acdk/tools/aunit/TestUnit.h(214):
      acdk::tools::aunit::TestCaller::runTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestUnit.cpp(81):
      acdk::tools::aunit::TestCase::run
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(61):
      acdk::tools::aunit::TestRunner::executeTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(150):
      acdk::tools::aunit::TestRunner::executeTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(249):
      acdk::tools::aunit::TestRunner::executeTests
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(278):
      acdk::tools::aunit::TestRunner::testmain
  C:\d\artefaktur\acdk\acdk_core\src\acdk\lang\System.cpp(972):
      acdk::lang::System::main2
  C:\d\artefaktur\acdk\acdk_core\src\acdk\lang\System.cpp(902):
      acdk::lang::System::main

pointer: 0x15da514; size=80; type=2;
allocated at:
  C:\d\artefaktur\acdk\acdk_core\src\acdk\lang\Object.cpp(142):
      acdk::lang::ObjectBase::operator new
  C:\d\artefaktur\acdk\acdk_core\src\acdk\lang\StringBuffer.cpp(51):
      acdk::lang::StringBuffer::StringBuffer
  C:\d\artefaktur\acdk\acdk_core\tests\acdk\lang\acdk_lang_String2_Test.cpp(232):
      tests::acdk::lang::String2_Test::memuse
  ../../../../include\acdk/tools/aunit/TestUnit.h(214):
      acdk::tools::aunit::TestCaller::runTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestUnit.cpp(81):
      acdk::tools::aunit::TestCase::run
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(61):
      acdk::tools::aunit::TestRunner::executeTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(150):
      acdk::tools::aunit::TestRunner::executeTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(249):
      acdk::tools::aunit::TestRunner::executeTests
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(278):
      acdk::tools::aunit::TestRunner::testmain
  C:\d\artefaktur\acdk\acdk_core\src\acdk\lang\System.cpp(972):
      acdk::lang::System::main2

pointer: 0x15da588; size=256; type=5;
allocated at:
  ../src\acdk/lang/ObjectBase.h(219):
      acdk::lang::ObjectBase::allocate
  C:\d\artefaktur\acdk\acdk_core\src\acdk\lang\StringBuffer.cpp(51):
      acdk::lang::StringBuffer::StringBuffer
  C:\d\artefaktur\acdk\acdk_core\tests\acdk\lang\acdk_lang_String2_Test.cpp(232):
      tests::acdk::lang::String2_Test::memuse
  ../../../../include\acdk/tools/aunit/TestUnit.h(214):
      acdk::tools::aunit::TestCaller::runTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestUnit.cpp(81):
      acdk::tools::aunit::TestCase::run
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(61):
      acdk::tools::aunit::TestRunner::executeTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(150):
      acdk::tools::aunit::TestRunner::executeTest
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(249):
      acdk::tools::aunit::TestRunner::executeTests
  C:\d\artefaktur\acdk\acdk_core\src\acdk\tools\aunit\TestRunner.cpp(278):
      acdk::tools::aunit::TestRunner::testmain
  C:\d\artefaktur\acdk\acdk_core\src\acdk\lang\System.cpp(972):
      acdk::lang::System::main2