Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/331#discussion_r80635357
--- Diff:
utils/common/src/main/java/org/apache/brooklyn/util/javalang/MemoryUsageTracker.java
---
@@ -68,5 +87,76 @@ public long getBytesUsed() {
memoryTrackedReferences.cleanUp();
return bytesUsed.get();
}
+
+ /** forces all soft references to be cleared by trying to allocate an
enormous chunk of memory,
+ * returns a description of what was done
+ * (tune with {@link #forceClearSoftReferences(long, int)}
+ * for greater than 200M precision in the output message, if you
really care about that) */
+ public static String forceClearSoftReferences() {
+ return forceClearSoftReferences(1000*1000, Integer.MAX_VALUE);
+ }
+ /** as {@link #forceClearSoftReferences()} but gives control over
headroom and max chunk size.
+ * it tries to undershoot by headroom as it approaches maximum (and
then overshoot)
+ * to minimize the chance we take exactly all the memory and starve
another thread;
+ * and it uses the given max chunk size in cases where the caller
wants more precision
+ * (the available memory will be fragmented so the smaller the chunks
the more it can
+ * fill in, but at the expense of time and actual memory provisioned)
*/
+ public static String forceClearSoftReferences(long headroom, int
maxChunk) {
--- End diff --
`headroom` not used.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---