• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Hons-and-memoization
      • Events
      • History
      • Parallelism
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Memoize
        • Mbe
        • Io
        • Apply$
        • Defpkg
        • Mutual-recursion
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Loop$-primer
        • Fast-alists
        • Defmacro
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
          • Normed
          • Hons-note
          • Hons-resize
          • Hons-wash
          • Hons-clear
          • Hons-copy
          • Maybe-wash-memory
            • Hons-equal
            • Hons-summary
            • Hons-equal-lite
            • Hons-sublis
            • Hons-wash!
            • Hons-clear!
            • Hons-copy-persistent
          • ACL2-built-ins
          • Developers-guide
          • System-attachments
          • Advanced-features
          • Set-check-invariant-risk
          • Numbers
          • Irrelevant-formals
          • Efficiency
          • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
          • Redefining-programs
          • Lists
          • Invariant-risk
          • Errors
          • Defabbrev
          • Conses
          • Alists
          • Set-register-invariant-risk
          • Strings
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Defmacro-untouchable
          • Primitive
          • <<
          • Revert-world
          • Set-duplicate-keys-action
          • Unmemoize
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Defopen
          • Sleep
        • Start-here
        • Real
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Hons

    Maybe-wash-memory

    Conditionally trigger a hons-wash and also clear-memoize-tables to reclaim memory. (CCL only; requires a trust tag)

    (maybe-wash-memory n &optional clear) will clear out unused honses and throw away all currently memoized results, but only if fewer than n bytes of memory are currently free. If more than n bytes are free, it does nothing.

    The general idea here is that garbage collection is slow, so you only want to do it if you are starting to run out of memory. At the same time, garbage collection is cheaper if you can do it "in between" computations that are creating a lot of garbage, where there are fewer live objects. Moreover, if you still have a lot of memory still available, then you may prefer to keep currently memoized results so that you aren't repeating work.

    You can use maybe-wash-memory in between computations to trigger garbage collections in an opportunistic way: if there's ample memory still available, no GC will be triggered, but if memory is getting scarce, then it's time to trigger an expensive collection, wiping out the memo tables and cleaning up honses in the process.

    Here's a basic example:

    (include-book "centaur/misc/memory-mgmt" :dir :system) ;; adds ttag
    (value-triple (set-max-mem (* 8 (expt 2 30))))           ;; 8 GB
    ... some memory intensive stuff ...
    (value-triple (maybe-wash-memory (* 3 (expt 2 30))))
    ... more memory intensive stuff ...
    (value-triple (maybe-wash-memory (* 3 (expt 2 30))))
    ... etc ...

    If the optional clear argument is t, honses will be cleared using hons-clear instead of hons-wash. (This is generally ill advised.)

    This can be a good way to clean up memory in between def-gl-param-thm cases, and in other situations.