
org.pepsoft.util.MemoryUtils Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.pepsoft.util;
import org.pepsoft.util.mdc.MDCCapturingRuntimeException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import static org.pepsoft.util.SystemUtils.JAVA_9;
import static org.pepsoft.util.SystemUtils.JAVA_VERSION;
/**
*
* @author pepijn
*/
public class MemoryUtils {
/**
* Get the memory used by a particular object instance in bytes. To prevent runaway
*
* @param object The object of which to determine the memory used.
* @param stopAt Types of references which should not be followed.
* @return The number of bytes of RAM used by the object, or -1 if the size
* could not be determined.
*/
public static int getSize(Object object, Set> stopAt) {
if (object == null) {
return 0;
} else if (JAVA_VERSION.isAtLeast(JAVA_9)) {
// TODO: support Java 9
return -1;
} else {
IdentityHashMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy