arrayfire / forge

High Performance Visualization
224 stars 48 forks source link

It seems memory leaking #101

Closed deism closed 8 years ago

deism commented 8 years ago

Hi,

I need to display a multi-frame data file, when I keep drawing FG window, the memory is growing, below is details:

  1. OS windows 10 64 bit
  2. FORGE dev version, 32 bit compilation, OpenGL 1.2 in Nvidia cuda sdk 7.5
  3. Data set: 1024 x 1024, 500 Frames, 8 bit gray scale
  4. The destructor of fg::Image fails to delete the memory which is newed by constructor
  5. Code sample:
for (int i = 0; i < 10000; i++)
{
    cout << "run " << i << endl;
    af::array s = af::array(h, w, data);
    unsigned char* dev_out = s.device<unsigned char>();

    fg::Image img(w, h, FG_GRAYSCALE, fg::u8);

    GfxHandle* handle = 0;
    createGLBuffer(&handle, img.pbo(), FORGE_PBO);
    copyToGLBuffer(handle, (ComputeResourceHandle)dev_out, img.size(););

    wnd.draw(img);

    releaseGLBuffer(handle);
    s.unlock();
}
9prady9 commented 8 years ago

@deism forge requires OpenGL >= 3.3 minimum. I am not sure how you are able to use OpenGL 1.2 (based on your bullet point (2)). Can you confirm your OpenGL version, may be what you are seeing is side effect of version mismatch problem.

deism commented 8 years ago

oops! my mistake, OpenCL version is 1.2 in Nvidia cuda sdk 7.5

deism commented 8 years ago

I also found memory growing in draw function of Class Window. Let's say 1024 x 1024 image at 8 FPS, the memory grows 4k per second.

deism commented 8 years ago

The memory stops growing after 1200 frames, This may be the mechanism of openCL, anyway, there is memory issue in the destructor of fg::Image, I have to make image as global object to avoid running out of memory

pavanky commented 8 years ago

@deism what version of arrayfire are you using ? Does the memory problem still occur if you don't do any forge related calls ? (i.e. a simple device() followed by unlock()) ?

deism commented 8 years ago

@pavanky I checked out master and dev on 16-08-09, both have same issue. If I don't call forge there is no problem. but simply calling forge as below will reproduce issue:

for (int i = 0; i < 10000; i++) { cout << "run " << i << endl; fg::Image img(w, h, FG_GRAYSCALE, fg::u8); }

9prady9 commented 8 years ago

@deism I am able to reproduce the issue on my end and looking into the issue.

9prady9 commented 8 years ago

@deism I have fixed this problem and the corresponding changes are part of the PR #89 . I will keep this open until the PR is merged. Thank you for reporting the problem.

deism commented 8 years ago

Well done, thanks.