<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Is it possible to delete graphic object from the GraphicsOverlay? (remove from the heap!) in Qt Maps SDK Questions</title>
    <link>https://community.esri.com/t5/qt-maps-sdk-questions/is-it-possible-to-delete-graphic-object-from-the/m-p/366019#M1834</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;ArcGIS ideology uses an overlay model for representing&amp;nbsp; maps and objects on them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I want to create some object allocated on the heap, I write:&lt;/P&gt;&lt;P&gt;Graphic* obj = new Graphic(this); (and something inside)&lt;/P&gt;&lt;P&gt;Next step, I put this object to overlay:&lt;/P&gt;&lt;PRE class="" style="color: #666666; background-color: #ffffff; font-size: 14px;"&gt;m_graphicsOverlay&lt;SPAN class=""&gt;-&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;graphics&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;append&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;graphic&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;If I have a pointer to the object, I can manually delete it, if I want!&lt;/P&gt;&lt;P&gt;for example: delete obj;&lt;BR /&gt;I did it and all my application has crashed!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;How can I delete an interesting item from overlay and also from the heap,&amp;nbsp; I want to avoid memory leackege !&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Jan 2018 14:15:45 GMT</pubDate>
    <dc:creator>GeorgeArnaut</dc:creator>
    <dc:date>2018-01-15T14:15:45Z</dc:date>
    <item>
      <title>Is it possible to delete graphic object from the GraphicsOverlay? (remove from the heap!)</title>
      <link>https://community.esri.com/t5/qt-maps-sdk-questions/is-it-possible-to-delete-graphic-object-from-the/m-p/366019#M1834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;ArcGIS ideology uses an overlay model for representing&amp;nbsp; maps and objects on them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I want to create some object allocated on the heap, I write:&lt;/P&gt;&lt;P&gt;Graphic* obj = new Graphic(this); (and something inside)&lt;/P&gt;&lt;P&gt;Next step, I put this object to overlay:&lt;/P&gt;&lt;PRE class="" style="color: #666666; background-color: #ffffff; font-size: 14px;"&gt;m_graphicsOverlay&lt;SPAN class=""&gt;-&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;graphics&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;append&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;graphic&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;If I have a pointer to the object, I can manually delete it, if I want!&lt;/P&gt;&lt;P&gt;for example: delete obj;&lt;BR /&gt;I did it and all my application has crashed!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;How can I delete an interesting item from overlay and also from the heap,&amp;nbsp; I want to avoid memory leackege !&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jan 2018 14:15:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/qt-maps-sdk-questions/is-it-possible-to-delete-graphic-object-from-the/m-p/366019#M1834</guid>
      <dc:creator>GeorgeArnaut</dc:creator>
      <dc:date>2018-01-15T14:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to delete graphic object from the GraphicsOverlay? (remove from the heap!)</title>
      <link>https://community.esri.com/t5/qt-maps-sdk-questions/is-it-possible-to-delete-graphic-object-from-the/m-p/366020#M1835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi George,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for getting in touch. The behavior you are seeing is expected because, as you say, the GraphicListModel does not take ownership of the Graphics which you append to it. You do need to manage the lifetime of these objects yourself - one approach is to use another QObject as the parent of the Graphic, rather than "this".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, for example, you could have a member variable (QObject* m_graphicsParent) on your class which you allocate prior to creating the graphics. Then each graphic would be created like so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Graphic* obj = new Graphic(m_graphicsParent);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Then when you come to remove the Graphics you can just call:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;delete m_graphicsParent;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;m_graphicsOverlay-&amp;gt;clear();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;The above approach is for the case where you are adding and removing all of the graphics in the overlay in each pass - otherwise you may need to delete the graphics separately and call GraphicListModel::removeOne etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;I hope that helps,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Luke&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jan 2018 16:34:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/qt-maps-sdk-questions/is-it-possible-to-delete-graphic-object-from-the/m-p/366020#M1835</guid>
      <dc:creator>LukeSmallwood</dc:creator>
      <dc:date>2018-01-15T16:34:19Z</dc:date>
    </item>
  </channel>
</rss>

