Memory Leak happens when we are updating QImage with picturemarkersymbol during runtime.

1164
7
Jump to solution
09-24-2023 10:37 PM
PrasathArunachalam
New Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
GuillaumeBelz
Esri Contributor

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)

View solution in original post

7 Replies
LucasDanzinger
Esri Frequent Contributor

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 

0 Kudos
PrasathArunachalam
New Contributor

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

0 Kudos
PrasathArunachalam
New Contributor

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.
}

0 Kudos
GuillaumeBelz
Esri Contributor

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?

  • which platform?
  • which version of SDK?
  • are you using QtWidgets or QtQuick? Is it 2D map or 3D scene?
  • a minimal code to reproduce the issue if possible

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. 

0 Kudos
PrasathArunachalam
New Contributor

 

Basic system setup details,

Platform -> Ubuntu 20.04

arcGIS version -> 100.7

Using Qt 5.15.2 QtQuick and 2D map

 

0 Kudos
GuillaumeBelz
Esri Contributor

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)

PrasathArunachalam
New Contributor

Hi,

 

Thank you for guiding us and now working fine after updating sdk version to 100.15.

 

Regards.

0 Kudos