Module: Lich::Util::MemoryReleaser
- Defined in:
- documented/util/memoryreleaser.rb
Overview
Memory management module that provides automatic and manual memory release functionality for Ruby applications. Supports Linux, macOS, and Windows platforms.
This module uses a singleton pattern to manage a background thread that periodically releases memory back to the operating system after running Ruby's garbage collector.
Settings are persisted per-character using InstanceSettings and include:
- auto_start: automatically start the memory releaser on module load
- interval: time in seconds between memory releases
- verbose: enable detailed logging
Defined Under Namespace
Classes: Manager
Constant Summary collapse
- DEFAULT_SETTINGS =
Default settings for memory releaser
{ auto_start: true, # Disabled by default, user must enable interval: 900, # default of 15 minutes verbose: false, }.freeze
Class Attribute Summary collapse
-
.command_queue ⇒ Queue
readonly
The command queue for communicating with the launcher thread.
-
.worker_thread ⇒ Thread?
readonly
The current worker thread.
Class Method Summary collapse
-
.auto_disable! ⇒ void
Disable auto-start and stop the memory releaser.
-
.auto_start! ⇒ Thread?
Enable auto-start and start the memory releaser.
-
.benchmark ⇒ void
Run a memory release benchmark.
-
.instance ⇒ Manager
Get or create the singleton Manager instance.
-
.interval!(seconds) ⇒ Integer
Update the interval setting.
-
.release ⇒ void
Perform a manual memory release.
-
.reset! ⇒ void
Reset the singleton instance.
-
.running? ⇒ Boolean
Check if the background thread is running.
-
.start(interval: nil, verbose: nil) ⇒ Thread?
Start the background memory release thread.
-
.status ⇒ Hash
Get the current status.
-
.stop ⇒ void
Stop the background memory release thread.
-
.verbose!(enabled) ⇒ Boolean
Update the verbose setting.
Class Attribute Details
.command_queue ⇒ Queue (readonly)
Returns the command queue for communicating with the launcher thread.
802 803 804 |
# File 'documented/util/memoryreleaser.rb', line 802 def command_queue @command_queue end |
.worker_thread ⇒ Thread? (readonly)
Returns the current worker thread.
807 808 809 |
# File 'documented/util/memoryreleaser.rb', line 807 def worker_thread @worker_thread end |
Class Method Details
.auto_disable! ⇒ void
This method returns an undefined value.
Disable auto-start and stop the memory releaser
860 861 862 |
# File 'documented/util/memoryreleaser.rb', line 860 def auto_disable! instance.auto_disable! end |
.auto_start! ⇒ Thread?
Enable auto-start and start the memory releaser
852 853 854 |
# File 'documented/util/memoryreleaser.rb', line 852 def auto_start! instance.auto_start! end |
.benchmark ⇒ void
This method returns an undefined value.
Run a memory release benchmark
910 911 912 |
# File 'documented/util/memoryreleaser.rb', line 910 def benchmark instance.benchmark end |
.instance ⇒ Manager
Get or create the singleton Manager instance
If auto_start is enabled in settings, automatically starts the memory releaser.
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 |
# File 'documented/util/memoryreleaser.rb', line 814 def instance @mutex ||= Mutex.new @mutex.synchronize { @instance ||= begin manager = Manager.new # Auto-start if enabled in settings if manager.settings[:auto_start] manager.start end manager end } end |
.interval!(seconds) ⇒ Integer
Update the interval setting
869 870 871 |
# File 'documented/util/memoryreleaser.rb', line 869 def interval!(seconds) instance.interval!(seconds) end |
.release ⇒ void
This method returns an undefined value.
Perform a manual memory release
886 887 888 |
# File 'documented/util/memoryreleaser.rb', line 886 def release instance.release end |
.reset! ⇒ void
This method returns an undefined value.
Reset the singleton instance
Stops the current instance if running and clears the singleton. Useful for testing or when you need to recreate the instance.
920 921 922 923 |
# File 'documented/util/memoryreleaser.rb', line 920 def reset! @instance&.stop @instance = nil end |
.running? ⇒ Boolean
Check if the background thread is running
894 895 896 |
# File 'documented/util/memoryreleaser.rb', line 894 def running? instance.running? end |
.start(interval: nil, verbose: nil) ⇒ Thread?
Start the background memory release thread
836 837 838 |
# File 'documented/util/memoryreleaser.rb', line 836 def start(interval: nil, verbose: nil) instance.start(interval: interval, verbose: verbose) end |
.status ⇒ Hash
Get the current status
902 903 904 |
# File 'documented/util/memoryreleaser.rb', line 902 def status instance.status end |
.stop ⇒ void
This method returns an undefined value.
Stop the background memory release thread
844 845 846 |
# File 'documented/util/memoryreleaser.rb', line 844 def stop instance.stop end |
.verbose!(enabled) ⇒ Boolean
Update the verbose setting
878 879 880 |
# File 'documented/util/memoryreleaser.rb', line 878 def verbose!(enabled) instance.verbose!(enabled) end |