简体   繁体   English

如何释放 LWJGL 分配的 memory

[英]How to free memory allocated by LWJGL

My Java application with LWJGL allocates memory indefinitely until the application is dropped.我的 Java 应用程序与 LWJGL 无限期地分配 memory 直到应用程序被删除。 Apparently this part of the code is causing the allocation of memory in looping.显然这部分代码导致 memory 在循环中的分配。 Is there a memory release missing?是否缺少 memory 版本? Tks for help.求帮助。

public void renderMesh(GameObject object, Camera camera) {
    GL30.glBindVertexArray(object.getMesh().getVAO());
    GL30.glEnableVertexAttribArray(0);
    GL30.glEnableVertexAttribArray(1);
    GL30.glEnableVertexAttribArray(2);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, object.getMesh().getIBO());
    
    shader.bind();
    shader.setUniform("model", Matrix4f.transform(object.getPosition(), object.getRotate(), object.getScale()));
    shader.setUniform("view", Matrix4f.view(camera.getPosition(), camera.getRotation()));
    shader.setUniform("projection", window.getProjectionMatrix());
    
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL13.glBindTexture(GL11.GL_TEXTURE_2D, object.getMesh().getMaterial(0).getTextureID());

    GL11.glDrawElements(GL11.GL_TRIANGLES, object.getMesh().getIndices().length, GL11.GL_UNSIGNED_INT, 0);
    
    shader.unbind();
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
        
    GL30.glDisableVertexAttribArray(0);
    GL30.glDisableVertexAttribArray(1);
    GL30.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
}

In your code there is nothing explicitly freeable.在您的代码中,没有任何内容可以明确释放。 But there are possibly two elements:但可能有两个要素:

  1. Are you sure to free resources and buffers used by meshes of your object?您确定释放 object 的网格使用的资源和缓冲区吗?
  2. And did you delete your shader program after use?你在使用后是否删除了你的着色器程序?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM