Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / base / nsMemory.h
blob7fda7ae83726f4316a7ac5ba74ecff44d85dd4ca
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsMemory_h__
8 #define nsMemory_h__
10 #include "nsError.h"
12 /**
14 * A client that wishes to be notified of low memory situations (for
15 * example, because the client maintains a large memory cache that
16 * could be released when memory is tight) should register with the
17 * observer service (see nsIObserverService) using the topic
18 * "memory-pressure". There are specific types of notifications
19 * that can occur. These types will be passed as the |aData|
20 * parameter of the of the "memory-pressure" notification:
22 * "low-memory"
23 * This will be passed as the extra data when the pressure
24 * observer is being asked to flush for low-memory conditions.
26 * "low-memory-ongoing"
27 * This will be passed when we continue to be in a low-memory
28 * condition and we want to flush caches and do other cheap
29 * forms of memory minimization, but heavy handed approaches like
30 * a GC are unlikely to succeed.
32 * "heap-minimize"
33 * This will be passed as the extra data when the pressure
34 * observer is being asked to flush because of a heap minimize
35 * call.
38 // This is implemented in nsMemoryImpl.cpp.
40 namespace nsMemory {
42 /**
43 * Attempts to shrink the heap.
44 * @param immediate - if true, heap minimization will occur
45 * immediately if the call was made on the main thread. If
46 * false, the flush will be scheduled to happen when the app is
47 * idle.
48 * @throws NS_ERROR_FAILURE if 'immediate' is set and the call
49 * was not on the application's main thread.
51 nsresult HeapMinimize(bool aImmediate);
53 /**
54 * This predicate can be used to determine if the platform is a "low-memory"
55 * platform. Callers may use this to dynamically tune their behaviour
56 * to favour reduced memory usage at the expense of performance. The value
57 * returned by this function will not change over the lifetime of the process.
59 bool IsLowMemoryPlatform();
60 } // namespace nsMemory
62 #endif // nsMemory_h__