gi-gio-2.0.32: Gio bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | Safe-Inferred
Language | Haskell2010

GI.Gio.Interfaces.MemoryMonitor

Contents

- Exported types
- Methods
  - dupDefault
- Signals
  - lowMemoryWarning

Description

`GMemoryMonitor` will monitor system memory and suggest to the application when to free memory so as to leave more room for other applications. It is implemented on Linux using the Low Memory Monitor (API documentation).

There is also an implementation for use inside Flatpak sandboxes.

Possible actions to take when the signal is received are:

- Free caches
- Save files that haven’t been looked at in a while to disk, ready to be reopened when needed
- Run a garbage collection cycle
- Try and compress fragmented allocations
- Exit on idle if the process has no reason to stay around
- Call `malloc_trim(3)`) to return cached heap pages to the kernel (if supported by your libc)

Note that some actions may not always improve system performance, and so should be profiled for your application. `malloc_trim()`, for example, may make future heap allocations slower (due to releasing cached heap pages back to the kernel).

See [type`gio`.MemoryMonitorWarningLevel] for details on the various warning levels.

### c code

    static void
    warning_cb (GMemoryMonitor *m, GMemoryMonitorWarningLevel level)
    {
      g_debug ("Warning level: %d", level);
      if (warning_level > G_MEMORY_MONITOR_WARNING_LEVEL_LOW)
        drop_caches ();
    }

    static GMemoryMonitor *
    monitor_low_memory (void)
    {
      GMemoryMonitor *m;
      m = g_memory_monitor_dup_default ();
      g_signal_connect (G_OBJECT (m), "low-memory-warning",
                        G_CALLBACK (warning_cb), NULL);
      return m;
    }

Don’t forget to disconnect the MemoryMonitor::lowMemoryWarning signal, and unref the `GMemoryMonitor` itself when exiting.

Since: 2.64

Synopsis

- newtype MemoryMonitor = MemoryMonitor (ManagedPtr MemoryMonitor)
- class (GObject o, IsDescendantOf MemoryMonitor o) => IsMemoryMonitor o
- toMemoryMonitor :: (MonadIO m, IsMemoryMonitor o) => o -> m MemoryMonitor
- memoryMonitorDupDefault :: (HasCallStack, MonadIO m) => m MemoryMonitor
- type MemoryMonitorLowMemoryWarningCallback = MemoryMonitorWarningLevel -> IO ()
- afterMemoryMonitorLowMemoryWarning :: (IsMemoryMonitor a, MonadIO m) => a -> ((?self :: a) => MemoryMonitorLowMemoryWarningCallback) -> m SignalHandlerId
- onMemoryMonitorLowMemoryWarning :: (IsMemoryMonitor a, MonadIO m) => a -> ((?self :: a) => MemoryMonitorLowMemoryWarningCallback) -> m SignalHandlerId

# Exported types

newtype MemoryMonitor Source #

Memory-managed wrapper type.

Constructors

MemoryMonitor (ManagedPtr MemoryMonitor) |

#### Instances

Instances details

Eq MemoryMonitor Source # |
Instance details Defined in GI.Gio.Interfaces.MemoryMonitor Methods (==) :: MemoryMonitor -> MemoryMonitor -> Bool Source # (/=) :: MemoryMonitor -> MemoryMonitor -> Bool Source #
GObject MemoryMonitor Source # |
Instance details Defined in GI.Gio.Interfaces.MemoryMonitor
ManagedPtrNewtype MemoryMonitor Source # |
Instance details Defined in GI.Gio.Interfaces.MemoryMonitor Methods toManagedPtr :: MemoryMonitor -> ManagedPtr MemoryMonitor Source #
TypedObject MemoryMonitor Source # |
Instance details Defined in GI.Gio.Interfaces.MemoryMonitor Methods glibType :: IO GType Source #
HasParentTypes MemoryMonitor Source # |
Instance details Defined in GI.Gio.Interfaces.MemoryMonitor
IsGValue (Maybe MemoryMonitor) Source # | Convert `MemoryMonitor` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.Gio.Interfaces.MemoryMonitor Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe MemoryMonitor -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe MemoryMonitor) Source #
type ParentTypes MemoryMonitor Source # |
Instance details Defined in GI.Gio.Interfaces.MemoryMonitor type ParentTypes MemoryMonitor = '[Initable, Object]

class (GObject o, IsDescendantOf MemoryMonitor o) => IsMemoryMonitor o Source #

Type class for types which can be safely cast to `MemoryMonitor`, for instance with `toMemoryMonitor`.

#### Instances

Instances details

(GObject o, IsDescendantOf MemoryMonitor o) => IsMemoryMonitor o Source # |
Instance details Defined in GI.Gio.Interfaces.MemoryMonitor

toMemoryMonitor :: (MonadIO m, IsMemoryMonitor o) => o -> m MemoryMonitor Source #

Cast to `MemoryMonitor`, for types for which this is known to be safe. For general casts, use `castTo`.

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

bindProperty, bindPropertyFull, forceFloating, freezeNotify, getv, init, isFloating, notify, notifyByPspec, ref, refSink, runDispose, stealData, stealQdata, thawNotify, unref, watchClosure.

#### Getters

getData, getProperty, getQdata.

#### Setters

setData, setDataFull, setProperty.

## dupDefault

memoryMonitorDupDefault Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m MemoryMonitor | Returns: a new reference to the default `MemoryMonitor`

Gets a reference to the default `MemoryMonitor` for the system.

Since: 2.64

# Signals

## lowMemoryWarning

type MemoryMonitorLowMemoryWarningCallback Source #

Arguments

= MemoryMonitorWarningLevel | `level`: the `MemoryMonitorWarningLevel` warning level
-> IO () |

Emitted when the system is running low on free memory. The signal handler should then take the appropriate action depending on the warning level. See the `MemoryMonitorWarningLevel` documentation for details.

Since: 2.64

afterMemoryMonitorLowMemoryWarning :: (IsMemoryMonitor a, MonadIO m) => a -> ((?self :: a) => MemoryMonitorLowMemoryWarningCallback) -> m SignalHandlerId Source #

Connect a signal handler for the lowMemoryWarning signal, to be run after the default handler. When overloading is enabled, this is equivalent to

    after memoryMonitor #lowMemoryWarning callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit `?self` parameter. Note that this requires activating the `ImplicitParams` GHC extension.

onMemoryMonitorLowMemoryWarning :: (IsMemoryMonitor a, MonadIO m) => a -> ((?self :: a) => MemoryMonitorLowMemoryWarningCallback) -> m SignalHandlerId Source #

Connect a signal handler for the lowMemoryWarning signal, to be run before the default handler. When overloading is enabled, this is equivalent to

    on memoryMonitor #lowMemoryWarning callback