COMP 2012 Object-Oriented Programming and Data Structures

Dr.Memory Tutorial

Tutorial

drmemory (Dr. Memory) is an open-source memory profiler. A feature that is interesting for this course is detection for memory leaks. To enforce a high coding standard, your submissions will be checked for memory leaks.

Download drmemory

  • For Windows users, we recommend you to download the portable version.
  • For macOS users, click here. Double-click in Finder to decompress.
  • For Linux users, click here.

Running drmemory

Notes on Eclipse User

If you are using a managed build project in Eclipse (not a Makefile project), you need to use static linking so that you can run your program outside Eclipse.

Goto "Project" -> "Properties" -> "C/C++ Build" -> "Settings" -> "Tool Settings" tab -> "MinGW C++ Linker" -> "Miscellaneous" -> type "-static" in the "Linker flags" box.

Running drmemory on Windows

  1. Locate your program. If you are using Eclipse, then it is available at "Eclipse_Workspace"\"Project_Name"\Debug\"Project_Name".exe.
  2. Locate drmemory. It is located at bin64 folder after extraction.
  3. Simply drag and drop your program to drmemory.
  4. If the following error occurs, click "OK" to dismiss it.
  5. After a while, the output is shown in a text document.

Running drmemory on macOS

  1. Find the path to your program. You can reveal its path by dragging it from Finder onto a terminal.
  2. Find the path to drmemory.
  3. Run the following command in a terminal.
    path/to/drmemory -- path/to/your/program
    For example:
    /Users/kelvin/DrMemory-MacOS-2.3.0-1/bin64/drmemory -- /Users/kelvin/pa1/pa1
  4. If the following alert pops up, dismiss it.
  5. Then go to "System Preferences" > "Security & Privacy" > "General" > Click "Open Anyway". Rerun the command. Repeat this for all alerts.

Running drmemory on Linux

See the command for macOS. Make sure you run bin64/drmemory (NOT bin/drmemory!).

Result

At the end of the output, find the result for leak(s) and possible leak(s):


                      ~~Dr.M~~       0 unique,     0 total,      0 byte(s) of leak(s)
                      ~~Dr.M~~       0 unique,     0 total,      0 byte(s) of possible leak(s)
                    
If the number of bytes for both are 0, then your code is free from memory leaks. If the number of bytes are not zero, then your code is prone to memory leaks. Note: You can ignore the bytes for still-reachable allocation(s). They are not counted as memory leaks.

Menu
Page maintained by
  • Peng YUN
  • Email: pyun@cse.ust.hk
  • Last Modified:
Homepage