Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valgrind for macOS Mojave 10.14.2? Any alternatives?

Ok, so I saw that someone asked this question over 4 months ago. But it has been a decent time since Mojave has been out. Does anyone know how to get it working or possibly any alternatives so that I can check my programs for memory leaks. I am a student, so cost does matter but this is a requirement for several of my classes. I would prefer not to have to use a virtual machine considering they never run well on Macs. Any suggestions would be great. Thanks.

like image 599
Tanner Breckenridge Avatar asked Feb 07 '19 14:02

Tanner Breckenridge


People also ask

Does valgrind work on macOS?

Due to changes on how macOS bundles and loads system dylibs, Valgrind is currently unable to track memory allocation correctly and thus to report memory leaks on macOS 11 and later.

Does valgrind work on M1 Mac?

Valgrind does not seem to work on M1 Macs. Issue #5 · LouisBrunner/homebrew-valgrind · GitHub.


1 Answers

You have few options here.

  1. You can use XCode for development and run the code in Profile mode.

  2. You can start Instruments and attach to process

  3. You can run the code and use leaks to determine the leak size

> leaks 2419
Process:         LeakingTheMemory [2419]
Path:            /Users/USER/*/LeakingTheMemory
...
...
...
leaks Report Version: 4.0
Process 2419: 196 nodes malloced for 262162 KB
Process 2419: 26 leaks for 134217760 total leaked bytes.

    26 (128M) << TOTAL >>
      1 (64.0M) ROOT LEAK: 0x10b17c000 [67108864]
      1 (32.0M) ROOT LEAK: 0x105726000 [33554432]
      1 (16.0M) ROOT LEAK: 0x104726000 [16777216]
      1 (8.00M) ROOT LEAK: 0x103f26000 [8388608]
      1 (4.00M) ROOT LEAK: 0x103b26000 [4194304]
      1 (2.00M) ROOT LEAK: 0x103926000 [2097152]
      1 (1.00M) ROOT LEAK: 0x103826000 [1048576]
      1 (512K) ROOT LEAK: 0x1037a6000 [524288]
      1 (256K) ROOT LEAK: 0x103766000 [262144]
      1 (128K) ROOT LEAK: 0x103746000 [131072]
      1 (64.0K) ROOT LEAK: 0x103735000 [65536]
      1 (32.0K) ROOT LEAK: 0x7fa354007800 [32768]
      1 (16.0K) ROOT LEAK: 0x7fa354003800 [16384]
      1 (8.00K) ROOT LEAK: 0x7fa354001800 [8192]
      1 (4.00K) ROOT LEAK: 0x7fa354000800 [4096]
      1 (2.00K) ROOT LEAK: 0x7fa354000000 [2048]
      1 (1.00K) ROOT LEAK: 0x7fa353802000 [1024]
      1 (512 bytes) ROOT LEAK: 0x7fa3535000a0 [512]
      1 (256 bytes) ROOT LEAK: 0x7fa353402fa0 [256]
      1 (128 bytes) ROOT LEAK: 0x7fa353500020 [128]
      1 (64 bytes) ROOT LEAK: 0x7fa353600000 [64]
      1 (32 bytes) ROOT LEAK: 0x7fa353402d40 [32]
      1 (16 bytes) ROOT LEAK: 0x7fa353402eb0 [16]
      1 (16 bytes) ROOT LEAK: 0x7fa353402ec0 [16]
      1 (16 bytes) ROOT LEAK: 0x7fa353500000 [16]
      1 (16 bytes) ROOT LEAK: 0x7fa353500010 [16]
  1. You can use Malloc Debugging Features
like image 184
Oo.oO Avatar answered Sep 20 '22 03:09

Oo.oO