Memory leak while copying VImage before drawing #2733
-
Describe the bug
While trying to do so I get terrible memory leaks. To Reproduce
RAM diagnose output of Visual Studio Expected behavior Actual behavior Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Hi @MathemanFlo,
If you call I think what you need here is I tried: /* compile with
*
* g++ -g -Wall draw.cc `pkg-config vips-cpp --cflags --libs`
*/
#include <vips/vips.h>
#include <vector>
#include <vips/vips8>
using namespace std;
using namespace vips;
int main(int argc, char** argv)
{
VIPS_INIT(argv[0]);
VImage paintLayer = VImage::new_from_file(argv[1]);
vector<double> ink;
ink.push_back(127);
for (int n = 0; n < 100000; ++n)
{
paintLayer = paintLayer.copy_memory();
paintLayer.draw_circle(ink, 10, 10, 10);
}
return 0;
} And it runs in a steady 50mb on this PC. |
Beta Was this translation helpful? Give feedback.
Hi @MathemanFlo,
image = image.copy()
adds a null "copy" node to a pipeline. Pixels are copied between the two images, but they will have different metadata, so you can modify one without changing the other. If you do 100 of these in a row, you'll have a pipeline 100 nodes long (!!).If you call
.draw_circle()
on a pipeline, it'll allocate a memory area, render the image into it, then draw the circle. This means that every image on your 100 node pipeline will have a separate memory copy of your source image (!!).I think what you need here is
.copy_memory()
. This allocates ram, renders the image into it, and returns a new image which wraps that memory area. Because it breaks the pipeline,…