JNI的Java内存管理 [英] Java memory Management for JNI

查看:145
本文介绍了JNI的Java内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题:

  1. 如果我对某个方法进行了JNI调用而JNI方法泄漏了内存该怎么办.此方法完成后,JVM垃圾收集器将能够取回该内存.我听说JVM不管理JNI使用的堆空间吗?但是JNI使用的内存是Java进程使用的内存的一部分吗?

  1. 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 ?

推荐答案

  1. 否:"JNI框架不为在本机端执行的代码分配的非JVM内存资源提供任何自动垃圾收集"(套接字甚至是ProcessBuilder.可以使用 MappedByteBuffer 实现共享内存.
  1. 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).
  2. No, Java has sockets and indeed ProcessBuilder. Shared memory can be achieved with MappedByteBuffer.

这篇关于JNI的Java内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆