Arm Community
Arm Community
  • Site
  • User
  • Site
  • Search
  • User
  • Groups
    • Research Collaboration and Enablement
    • DesignStart
    • Education Hub
    • Innovation
    • Open Source Software and Platforms
  • Forums
    • AI and ML forum
    • Architectures and Processors forum
    • Arm Development Platforms forum
    • Arm Development Studio forum
    • Arm Virtual Hardware forum
    • Automotive forum
    • Compilers and Libraries forum
    • Graphics, Gaming, and VR forum
    • High Performance Computing (HPC) forum
    • Infrastructure Solutions forum
    • Internet of Things (IoT) forum
    • Keil forum
    • Morello Forum
    • Operating Systems forum
    • SoC Design and Simulation forum
    • 中文社区论区
  • Blogs
    • AI and ML blog
    • Announcements
    • Architectures and Processors blog
    • Automotive blog
    • Graphics, Gaming, and VR blog
    • High Performance Computing (HPC) blog
    • Infrastructure Solutions blog
    • Innovation blog
    • Internet of Things (IoT) blog
    • Operating Systems blog
    • Research Articles
    • SoC Design and Simulation blog
    • Tools, Software and IDEs blog
    • 中文社区博客
  • Support
    • Arm Support Services
    • Documentation
    • Downloads
    • Training
    • Arm Approved program
    • Arm Design Reviews
  • Community Help
  • More
  • Cancel
Arm Community blogs
Arm Community blogs
High Performance Computing (HPC) blog Detecting Memory Leaks
  • Blogs
  • Mentions
  • Sub-Groups
  • Tags
  • Jump...
  • Cancel
More blogs in Arm Community blogs
  • AI and ML blog

  • Announcements

  • Architectures and Processors blog

  • Automotive blog

  • Embedded blog

  • Graphics, Gaming, and VR blog

  • High Performance Computing (HPC) blog

  • Infrastructure Solutions blog

  • Internet of Things (IoT) blog

  • Operating Systems blog

  • SoC Design and Simulation blog

  • Tools, Software and IDEs blog

Tags
  • High Performance Computing (HPC)
  • Arm DDT
  • HPC Tools
  • Development Tools
  • infrastructure
Actions
  • RSS
  • More
  • Cancel
Related blog posts
Related forum threads

Detecting Memory Leaks

Mark O'Connor
Mark O'Connor
August 24, 2012
2 minute read time.

Memory leaks are a killer of long running applications - memory usage keeps growing until finally the memory supply is exhausted and it's "game over". If you’re lucky the system recognizes your application is at fault and terminates it. If you’re unlucky, the system itself will crash.

How do memory leaks come to exist and what are they?

Memory leaks happen when processes allocate memory and forget to release it. C and C++ developers, we know this type of memory as heap memory obtained by calls to malloc or new, for example. Fortran90 coders know this as allocatable memory - and use the allocateprimitive.

Allocatable memory is great but the infinite memory machine does not exist so you must take care to release the memory when you are done with it - allowing your application to reuse it the next time it needs some memory.

When you forget to deallocate, you’ve made a leak. If allocation happens repeatedly without being deallocated - your application will fail! C and C++ users know particularly well that allocations happen everywhere - so finding the leak can be a challenge.

How can we fix a memory leak?

One of my applications is dying - I know it’s due to memory exhaustion because “top” shows consumption growing, the machine is starting to whirr and grind at the disk as the swap memory kicks in, and finally the machine drops off the planet.

I fire up my favourite debugger - Arm DDT - it has a great built-in memory leak detector. This finds the most prominent leaks, and lets you fix them. I simply tick the “Memory Debugging” option when starting to debug the application.

After a few minutes, I pull up a chart to see how my memory is doing. This is a multi-process application using the MPI library - and one of the processes looks to be using more memory than the others.

Something big is stirring on Process 0

Arm DDT remembers the stack trace for each allocation, so that you can pinpoint which part of your code is wasting memory. I click on the largest block in bar chart (Packet::allocate on Process 0) to bring up the details.


Pinpointed!

That was handy - I know how large the allocation is and where it came from. I click again and Arm DDT leaps to the source code of my application!



The line of allocation

Things are clear straight away.

Packet object “p” is allocating memory - and the memory is used but when “p” goes out of scope it never calls deallocate. That was clumsy but it is easy to fix now, thanks to Arm DDT!

Read more about what the memory debugger can help with by visiting the memory debugging in Arm DDT page.

Anonymous
High Performance Computing (HPC) blog
  • Arm Compiler for Linux and Arm PL now available in Spack

    Annop Wongwathanarat
    Annop Wongwathanarat
    We are happy to announce that Arm Compiler for Linux (ACfL) and Arm Performance Libraries (Arm PL) are now available as installable packages in Spack, a widely used package manager in the HPC community…
    • May 22, 2023
  • Using vector math functions on Arm

    Chris Goodyer
    Chris Goodyer
    In this post, we highlight the scale of performance increases possible, detail the accuracy requirements, and explain in detail how to use the libamath library that ships with ACfL.
    • May 16, 2023
  • Arm Compiler for Linux and Arm Performance Libraries 23.04

    Chris Goodyer
    Chris Goodyer
    Arm Compiler for Linux 23.04 is now available with improved compilers and libraries. In this blog, we explore what is new in this first major release of 2023.
    • May 9, 2023