<dependency> <groupId>com.carrotsearch</groupId> <artifactId>java-sizeof</artifactId> <version>0.0.5</version> </dependency>
import com.carrotsearch.sizeof.RamUsageEstimator; import com.google.common.cache.Cache; import java.util.UUID; public class Test3 { // 10 秒钟过期 private static Cache<String, Integer> guavaCache = CacheFactory.cached(10L, null); public static void main(String[] args) { for (int i = 0; i < 100000; i++) { String id = UUID.randomUUID().toString(); guavaCache.put(id, i); } long size = RamUsageEstimator.sizeOf(guavaCache); System.out.println(size + " b"); long kb = size / 1024; System.out.println(kb + " kb"); long m = kb / 1024; System.out.println(m + " m"); } }
输出
20249888 b
19775 kb
19 m
10W数据,占19M
标签:kb,java,占用,内存大小,long,System,guavaCache,size From: https://www.cnblogs.com/acm-bingzi/p/java_memory.html