Scroll to navigation

Memory::Usage(3pm) User Contributed Perl Documentation Memory::Usage(3pm)


Memory::Usage - Tools to determine actual memory usage


Version 0.201


    use Memory::Usage;
    my $mu = Memory::Usage->new();
    # Record amount of memory used by current process
    $mu->record('starting work');
    # Do the thing you want to measure
    # Record amount in use afterwards
    $mu->record('after something_memory_intensive()');
    # Spit out a report


This module lets you attempt to measure, from your operating system's perspective, how much memory a process is using at any given time.


Class Methods

Creates a new Memory::Usage object. This object will contain usage state as recorded along the way.

Instance Methods

Record the memory usage at call time, logging it internally with the provided message. Optionally takes a process ID to record memory usage for, defaulting to the current process.
Generates report on memory usage.
Prints report on memory usage to stderr.
Return arrayref of internal state. Returned arrayref contains zero or more references to arrays with the following columns (in order). All sizes are in kilobytes.


Dave O'Neill, "<dmo at>"


Please report any bugs or feature requests to "bug-memory-usage at", or through the web interface at <>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Memory::Usage

You can also look for information at:


  • Memchmark

    Iteratively run coderefs (similar to Benchmark) and compare their memory usage. Useful for optimizing specific subroutines with large memory usage once you've identified them as memory hogs. Uses same technique for gathering usage information as this module, so accuracy and precision suffer similarly.

  • Devel::Size

    Show the size of Perl variables. Also useful for microoptimzations when you know what you're looking for. Looks at Perl internals, so accuracy is good.


Copyright 2010 Dave O'Neill.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

2018-10-29 perl v5.26.2