File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
src/Library/demos/Memory Monitor Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ using Gtk 4.0;
2+ using Adw 1;
3+
4+ Adw.StatusPage {
5+ title: _("Memory Monitor");
6+ description: _("Monitor system memory");
7+
8+ LinkButton {
9+ label: "API Reference";
10+ uri: "https://docs.gtk.org/gio/iface.MemoryMonitor.html";
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ import Gio from "gi://Gio" ;
2+
3+ const memory_monitor = Gio . MemoryMonitor . dup_default ( ) ;
4+
5+ const cache = new Map ( ) ;
6+ cache . set ( "a" , 1 ) ;
7+ cache . set ( "b" , 2 ) ;
8+ cache . set ( "c" , 3 ) ;
9+
10+ memory_monitor . connect ( "low-memory-warning" , ( monitor , level ) => {
11+ // Use inequalities for checking as new levels may be added in the future
12+ if ( level >= Gio . MemoryMonitorWarningLevel . LOW ) {
13+ // Processes should free up unneeded resources
14+ console . log ( "Warning Level: Low" ) ;
15+ drop_caches ( ) ;
16+ } else if ( level >= Gio . MemoryMonitorWarningLevel . MEDIUM ) {
17+ // Processes should try harder to free up unneeded resources
18+ console . log ( "Warning Level: Medium" ) ;
19+ } else if ( level >= Gio . MemoryMonitorWarningLevel . CRITICAL ) {
20+ // system will start terminating processes to reclaim memory
21+ console . log ( "Warning Level: Critical" ) ;
22+ }
23+ } ) ;
24+
25+ function drop_caches ( ) {
26+ cache . clear ( ) ;
27+ }
Original file line number Diff line number Diff line change 1+ {
2+ "category" : " platform" ,
3+ "description" : " Monitor system memory" ,
4+ "panels" : [" code" , " preview" ],
5+ "autorun" : true
6+ }
You can’t perform that action at this time.
0 commit comments