File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
src/Library/demos/Memory Monitor Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ #! / usr/ bin/ env - S vala workbench. vala -- pkg libadwaita- 1
2+
3+ private HashTable<string, int?> cache;
4+
5+ public void main () {
6+ cache = new HashTable<string, int?> (string . hash, str_equal);
7+ cache[" a" ] = 1 ;
8+ cache[" b" ] = 2 ;
9+ cache[" c" ] = 3 ;
10+
11+ var memory_monitor = MemoryMonitor . dup_default ();
12+ memory_monitor. low_memory_warning. connect ((level) = > {
13+ /*
14+ * Use inequalities for checking as new levels may be added in the future
15+ * See https://valadoc.org/gio-2.0/GLib.MemoryMonitorWarningLevel.html
16+ */
17+ if (level >= MemoryMonitorWarningLevel . LOW ) {
18+ // Processes should free up unneeded resources
19+ message (" Warning Level: Low" );
20+ drop_caches ();
21+ }
22+
23+ if (level >= MemoryMonitorWarningLevel . MEDIUM ) {
24+ // Processes should try harder to free unneeded resources
25+ message (" Warning Level: Medium" );
26+ }
27+
28+ if (level >= MemoryMonitorWarningLevel . CRITICAL ) {
29+ // The system will start terminating processes to reclaim memory
30+ message (" Warning Level: Critical" );
31+ }
32+ });
33+ }
34+
35+ private void drop_caches () {
36+ cache. remove_all ();
37+ }
You can’t perform that action at this time.
0 commit comments