Java memory Management for JNI(JNI 的 Java 内存管理)
问题描述
我有两个问题:
如果我有一个对方法的 JNI 调用并且 JNI 方法泄漏了内存怎么办.一旦此方法完成,JVM 垃圾收集器将能够取回该内存.听说JVM不管理JNI使用的堆空间?但是JNI使用的内存是Java进程使用的内存的一部分吗?
What if I have a JNI call to a method and the JNI method leaks memory. Once this method completes will the JVM Garbage collector be able to get that memory back. I heard that the JVM does not manage the Heap Space used by JNI ? But the memory used by JNI is a part of the memory used by the Java process ?
一定要使用JNI来实现IPC吗?还有哪些其他流行的 Java 技术,或者有没有开源库来实现 Java 中的共享内存?
Is it absolutely necessary to use JNI to achieve IPC ? What are the other popular Java techniques or is there a Open Source Library to achieve Shared memory in Java ?
推荐答案
- 否:JNI 框架不为在本机端执行的代码分配的非 JVM 内存资源提供任何自动垃圾回收"(维基百科).
- 不,Java 有 套接字 确实是 ProcessBuilder.可以使用 MappedByteBuffer 实现共享内存.
- No: "the JNI framework does not provide any automatic garbage collection for non-JVM memory resources allocated by code executing on the native side" (Wikipedia).
- No, Java has sockets and indeed ProcessBuilder. Shared memory can be achieved with MappedByteBuffer.
这篇关于JNI 的 Java 内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JNI 的 Java 内存管理


- 获取数字的最后一位 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01