- 添加依赖
<dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>4.0.0</version> </dependency>
- 添加vm启动参数
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED
- 编写测试代码
public static void main(String[] args) throws Exception { List<ChannelUserDTO> list = new ArrayList<>() ; for (int i = 0; i < 1000000; i++) { list.add(new ChannelUserDTO()) ; } log.info("size 2: {}", RamUsageEstimator.humanSizeOf(list)); }
Java获取对象占用内存
于 2023-09-07 15:21:50 首次发布