Messages on stdout, possibly memory leak? #4736
-
Bug reportDescribe the bug I traced this back to here which seems to be related to checking for memory leaks? But I was not able to figure out what this is for, nor if it indicates a problem. The part of my application that causes this is mipmap generation. I basically make an image from a memory buffer, then repeatedly half the size until it is at 1x1. At every step I copy the raw image data to my buffer. It looks something like this (using the cpp api): vips::VImage mip = vips::VImage::new_from_memory((void*)lt.data.data(), byte_size, lt.w, lt.h, lt.bands, lt.format);
const bool has_alpha = false;//lt.bands == 4; // TODO
size_t offset = byte_size;
while(mip.width() > 1 || mip.height() > 1) {
const size_t mip_w = ih::next_mip_size((size_t)mip.width());
const size_t mip_h = ih::next_mip_size((size_t)mip.height());
if(has_alpha) mip = mip.premultiply();
mip = mip.resize((double)mip_w/mip.width(), mip.option()->set("vscale", (double)mip_h/mip.height()));
if(has_alpha) mip = mip.unpremultiply();
IMV_ASSERT(mip_w == mip.width());
IMV_ASSERT(mip_h == mip.height());
vips::VRegion region = mip.region();
region.prepare(0, 0, mip_w, mip_h);
const size_t mip_size = mip_w*mip_h*(lt.bands)*elem_size;
imv::util::vips::region_to_mem(<.data[offset], lt.data.size()-offset, region.get_region());
lt.mip_levels.push_back(ih::MipLevel{
.data = std::span(<.data[offset], mip_size),
.size = glm::uvec2(mip_w, mip_h)
});
offset += mip_size;
}This is an example of the output: So is this an issue with my code? Is it an issue with libvips? Is it an issue at all? I hope this is not something obvious π , but I could not find any other information or issues about this, so I made this issue :). Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @Julianiolo, It's harmless debugging output, it shows you are computing some pixels many times. You are doing effectively this: So there's a chain of repeated resize operations. They will all execute, so the final level of the resize will compute some pixels (in this case) three times over. The trick is to use https://www.libvips.org/API/current/cpp/classVImage.html#a852b430469f8b63648cd8c006314cd72 Something like: Now each resize is generated to an area of RAM and those pixels are reused. You can get a pointer to this area of RAM with https://www.libvips.org/API/current/cpp/classVImage.html#af1ecdcc16fae9beb5e066535bfe093c6 Perhaps: This data will get freed in the next loop, so take a copy, or make a reference to every |
Beta Was this translation helpful? Give feedback.
Hi @Julianiolo,
It's harmless debugging output, it shows you are computing some pixels many times.
You are doing effectively this:
So there's a chain of repeated resize operations. They will all execute, so the final level of the resize will compute some pixels (in this case) three times over.
The trick is to use
copy_memory()to make sure the result of each resize stage gets reused.https://www.libvips.org/API/current/cpp/classVImage.html#a852b430469f8b63648cd8c006314cd72
Something like:
Now each resize is generated to an area of RAM and those pixels are reused.
Yβ¦