I am trying to load the image at runtime by calling the function_under_test() and as well add a picture marker symbol every time ,this has resulted in memory leak and when we try to clear it using the api scvImageGraphiOverLay->graphics()->clear(); still i have memory leaks .
void function_under_test(){
QByteArray data;
if(!file.open(QIODevice::ReadOnly))
{
return;
}
else
{
data=file.readAll();
}
file.close();
const unsigned char* lpchar = reinterpret_cast<const unsigned char *>(data.constData());
// Point pt1(airCraftPoint);
QImage testImg(lpchar, 1080, 1080, QImage::Format_RGB888);
scvImageSymbol = new PictureMarkerSymbol(testImg, this);
scvImageSymbol->setOpacity(0.5);scvImagetGraphic->setSymbol(scvImageSymbol);
scvImageGraphiOverLay->graphics()->clear();
scvImageGraphiOverLay->graphics()->append(scvImagetGraphic);
}
How to resolve memory leak issue related to picturemarkersymbol.
Solved! Go to Solution.
Hello,
This is known issue and it was fixed in 100.14 (BUG-000145979 https://developers.arcgis.com/qt/v100/release-notes/prior-releases/release-notes-for-100-14/#issues-...).
Can you try with last version? (100.15 for Qt5 or 200.2 for Qt6)
It looks like you new up a picture marker symbol and set the parent to ‘this’, then the graphic is removed from the collection but not deleted. Calling clear on the graphics overlay will remove it from the collection but it won’t delete the object. https://developers.arcgis.com/qt/cpp/api-reference/esri-arcgisruntime-graphiclistmodel.html#clear
Try setting the parent object of the symbol the the graphic, and then deleting the graphic after calling clear. Either that or use some more sophisticated RAII technique
void function_under_test() {
QByteArray data;
if (!file.open(QIODevice::ReadOnly)) {
return;
} else {
data = file.readAll();
}
file.close();
const unsigned char* lpchar = reinterpret_cast<const unsigned char*>(data.constData());
QImage testImg(lpchar, 1080, 1080, QImage::Format_RGB888);
scvImageSymbol = new PictureMarkerSymbol(testImg, this);
// Create the graphic and set the symbol
scvImagetGraphic = new Graphic(airCraftPoint, scvImageSymbol);
scvImageGraphiOverLay->graphics()->clear();
// Add the graphic to the graphics overlay
scvImageGraphiOverLay->graphics()->append(scvImagetGraphic);
// Delete the graphic after clearing the overlay
delete scvImagetGraphic;
}
still memory is not deleted
also tried
std::shared_ptr<PictureMarkerSymbol> scvImageSymbol(new PictureMarkerSymbol(testImg, this));
std::weak_ptr<PictureMarkerSymbol> scvImageSymbol1(scvImageSymbol);
if (auto scvImageSymbol12 = scvImageSymbol1.lock()) {
scvImagetGraphic->setSymbol(scvImageSymbol.get());
// Now that the symbol is set, you can release the shared_ptr and let it go out of scope.
// This will automatically clean up the memory when there are no more references.
scvImageSymbol12.reset();
} else {
// Handle the case where the weak_ptr has expired (shared_ptr is no longer valid).
// You may want to log an error or take some appropriate action.
}
Hello,
I tried to reproduce this issue, but I can't detect a memory leak (200.3 on Mac).
Can you provide more details to reproduce it?
Off topic, is there a reason to use a raw buffer (QFile, QByteArray)? In your code, I guess there is a problem with the lifetime of the buffer. You can load an image directly with QImage:
QImage testImg(path_to_image);
Second point, 1080x1080 image is very big for a symbol.
Basic system setup details,
Platform -> Ubuntu 20.04
arcGIS version -> 100.7
Using Qt 5.15.2 QtQuick and 2D map
Hello,
This is known issue and it was fixed in 100.14 (BUG-000145979 https://developers.arcgis.com/qt/v100/release-notes/prior-releases/release-notes-for-100-14/#issues-...).
Can you try with last version? (100.15 for Qt5 or 200.2 for Qt6)
Hi,
Thank you for guiding us and now working fine after updating sdk version to 100.15.
Regards.