Module: Lich::Util::MemoryReleaser

Defined in:
documented/util/memoryreleaser.rb

Overview

Memory management module that provides automatic and manual memory release functionality Memory management module that provides automatic and manual memory release functionality

Examples:

Enabling auto-start

MemoryReleaser.auto_start!

Defined Under Namespace

Classes: Manager

Constant Summary collapse

DEFAULT_SETTINGS =

Default settings for memory releaser Default settings for memory releaser

{
  auto_start: false, # Disabled by default, user must enable
  interval: 900, # default of 15 minutes
  verbose: false,
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.command_queueObject (readonly)

Returns the value of attribute command_queue.



529
530
531
# File 'documented/util/memoryreleaser.rb', line 529

def command_queue
  @command_queue
end

.worker_threadObject (readonly)

Returns the value of attribute worker_thread.



531
532
533
# File 'documented/util/memoryreleaser.rb', line 531

def worker_thread
  @worker_thread
end

Class Method Details

.auto_disable!Boolean

Disables auto-start for the memory releaser using the singleton instance

Returns:

  • (Boolean)

    The status of auto-start after disabling



573
574
575
# File 'documented/util/memoryreleaser.rb', line 573

def auto_disable!
  instance.auto_disable!
end

.auto_start!Boolean

Enables auto-start for the memory releaser using the singleton instance

Returns:

  • (Boolean)

    The status of auto-start after enabling



567
568
569
# File 'documented/util/memoryreleaser.rb', line 567

def auto_start!
  instance.auto_start!
end

.benchmarkvoid

This method returns an undefined value.

Runs a benchmark to show memory usage before and after release using the singleton instance



611
612
613
# File 'documented/util/memoryreleaser.rb', line 611

def benchmark
  instance.benchmark
end

.instanceManager

Retrieves the singleton instance of the MemoryReleaser

Returns:

  • (Manager)

    The singleton instance of the Manager



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'documented/util/memoryreleaser.rb', line 535

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

Sets the interval for memory release using the singleton instance

Parameters:

  • seconds (Integer)

    The interval in seconds (minimum 60)

Returns:

  • (Integer)

    The new interval



580
581
582
# File 'documented/util/memoryreleaser.rb', line 580

def interval!(seconds)
  instance.interval!(seconds)
end

.releasevoid

This method returns an undefined value.

Releases memory using the singleton instance



593
594
595
# File 'documented/util/memoryreleaser.rb', line 593

def release
  instance.release
end

.reset!Object



615
616
617
618
# File 'documented/util/memoryreleaser.rb', line 615

def reset!
  @instance&.stop
  @instance = nil
end

.running?Boolean

Checks if the memory releaser worker is currently running using the singleton instance

Returns:

  • (Boolean)

    True if running, false otherwise



599
600
601
# File 'documented/util/memoryreleaser.rb', line 599

def running?
  instance.running?
end

.start(interval: nil, verbose: nil) ⇒ Thread?

Starts the memory releaser worker using the singleton instance

Parameters:

  • interval (Integer, nil) (defaults to: nil)

    The interval in seconds (optional)

  • verbose (Boolean, nil) (defaults to: nil)

    Whether to enable verbose logging (optional)

Returns:

  • (Thread, nil)

    The worker thread if started, otherwise nil



555
556
557
# File 'documented/util/memoryreleaser.rb', line 555

def start(interval: nil, verbose: nil)
  instance.start(interval: interval, verbose: verbose)
end

.statusHash

Retrieves the current status of the memory releaser using the singleton instance

Returns:

  • (Hash)

    The current status including running, enabled, auto_start, interval, verbose, and platform



605
606
607
# File 'documented/util/memoryreleaser.rb', line 605

def status
  instance.status
end

.stopvoid

This method returns an undefined value.

Stops the memory releaser worker using the singleton instance



561
562
563
# File 'documented/util/memoryreleaser.rb', line 561

def stop
  instance.stop
end

.verbose!(enabled) ⇒ Boolean

Sets the verbose mode for logging using the singleton instance

Parameters:

  • enabled (Boolean)

    Whether to enable verbose logging

Returns:

  • (Boolean)

    The new verbose status



587
588
589
# File 'documented/util/memoryreleaser.rb', line 587

def verbose!(enabled)
  instance.verbose!(enabled)
end