Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: MemoryMonitorLowmemorywarningCallback

[173:7] extends: object

Generated low-level callback wrapper for GIR callback low-memory-warning.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • MemoryMonitorLowmemorywarningCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, level, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.

class: MemoryMonitor

[36:7] extends: object

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 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 [signal@Gio.MemoryMonitor::low-memory-warning] signal, and unref the GMemoryMonitor itself when exiting.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • MemoryMonitor (Handle = null)

    Creates a new MemoryMonitor by wrapping a native handle or another wrapper.

    • @p Handle is the native handle or another wrapper whose handle to adopt.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • connectSignal (string Name, CallbackObj)

    Connects one generated callback wrapper to a named signal.

    • @p Name is the signal name.
    • @p CallbackObj is the generated callback wrapper to connect.
    • @r The connected handler id.
  • disconnectSignalHandler (int HandlerId)

    Disconnects one retained signal handler id.

    • @p HandlerId is the signal handler id to disconnect.
    • @r None.
  • setOnLowmemorywarning (callback Fn, UserData = null)

    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 #GMemoryMonitorWarningLevel documentation for details. Since the [iface@Gio.MemoryMonitor] is a singleton, this signal will be emitted in the [func@GLib.MainContext.default][global-default main context].

    • @p Fn is the Aussom callback.
    • @p Fn is called with (MemoryMonitor Self, string Level).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.

class: MemoryMonitorMeta

[244:14] static extends: object

Generated metadata helpers for MemoryMonitor interface surfaces.

Methods

  • signals ()

    Returns signal metadata for MemoryMonitor.

    • @r A list.