If you give us more information we should be able to help.
Meanwhile, these old nodes might give you a clue as to what your problem might be.
Using this node for Memory Tools References nowadays:
General Areas to consider when faced with a Memory Leak
- Stability: Once your process grows to a certain size, does it stay there, or does it grow further over time?
- Large CPAN Modules. Are you using any?
- Circular references. See Eliminate circular reference memory leak using weaken (Perl Maven).
- Scoping.
- File/Database handling.
- Tools. Try one or more from the following section.
Perl Tools and Advice
- Profiling Memory Usage talk by Tim Bunce (YAPC::NA Austin Texas 2013 featuring Devel::SizeMe). Resident size vs vm size, rss, segments, /proc/pid/maps (e.g. SO maps question), malloc and the heap, perl internals, pads, constant folding, arenas, recursion, perl data structures (lots of pointers), ... (update: this reply describes memory used by lexical variables in subroutines at the 09:20 minute mark)
- Plans for adding memory profiling to Devel::NYTProf
- Devel::NYTProf
- Devel::Gladiator
- Devel::LeakTrace
- Test::LeakTrace
- Devel::Leak
- Devel::FindRef
- Devel::Cycle
- Test::Memory::Cycle
- Devel::MemoryTrace::Light
- Mini-Tutorial: Perl's Memory Management by ikegami
- As pointed out by dave_the_m: "once the perl interpreter has exhausted all memory, there's very little it can do. There is a reserved fixed buffer to allow it to display the OOM error itself, but doing anything complex like displaying a Carp::confess()-like stack backtrace would require many memory allocations to generate the display, all of which would themselves fail".
General Tools
- Clang (Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages ... includes a static analyzer, and several code analysis tools ... Clang operates in tandem with the LLVM compiler back end)
- LLVM (LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture ... designed around a language-independent intermediate representation (IR) that serves as a portable, high-level assembly language that can be optimized with a variety of transformations over multiple passes)
- Boehm garbage collector aka Boehm–Demers–Weiser garbage collector (wikipedia)
Static Code Analysis
Code Profiling and Optimization
Testing Concurrent Software
Security Testing
Some Related PM Nodes
More Nodes Added Later
Recursion
- Profiling Memory Usage talk by Tim Bunce (YAPC::NA Austin Texas 2013 featuring Devel::SizeMe). Resident size vs vm size, rss, segments, /proc/pid/maps (e.g. SO maps question), malloc and the heap, perl internals, pads, constant folding, arenas, recursion, perl data structures (lots of pointers), ... (update: this reply describes memory used by lexical variables in subroutines at the 09:20 minute mark)
- Re^2: Perl Deep Recursion locks up modern linuxes? by me (2016)
- Re^3: Memory usage double expected (run-time) by me (2022)
- Re^3: How am i doing? by harangzsolt33 (2025) - "If it's a recursion, it needs to be written as a for loop or some kind of loop. If you see that your sub-routine calls itself, double check that. That's often a program design error" - this nonsense provoked many useful replies. :)
See Also
Updated: Many extra references were added long after the original reply was made.