<?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 Re: Memory leak when exporting images in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246530#M18429</link>
    <description>&lt;P&gt;Yes, I understand. There may be other important considerations that we are unaware of. I added your comment to the ticket, anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jun 2022 15:14:15 GMT</pubDate>
    <dc:creator>jeremy_tammik</dc:creator>
    <dc:date>2022-06-20T15:14:15Z</dc:date>
    <item>
      <title>Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246028#M18423</link>
      <description>&lt;P&gt;When calling the ExportImage method, there is a large unmanaged memory spike, this memory is not cleared after the transaction is completed, and remains occupied until Revit closes. Tested versions of Revit 2021-2023&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before the call: 1.01 GB&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1081846iB12D8487BC08E91A/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;After the call: 2.09 GB&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="9f6042e11b.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1081849i79F839C414EB11C2/image-size/large?v=v2&amp;amp;px=999" role="button" title="9f6042e11b.png" alt="9f6042e11b.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 11:52:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246028#M18423</guid>
      <dc:creator>nice3point</dc:creator>
      <dc:date>2022-06-20T11:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246224#M18424</link>
      <description>&lt;P&gt;Thank you very much for your report, Roman. The development team may well be aware of this. In order to make sure, I will gladly report it to them for closer analysis. A prerequisite for that is a minimal reproducible case in order to be able to efficiently set up, test and debug the behaviour locally:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you able to provide that? E.g., maybe an RVT containing a macro plus an image file (or a link to one) to load. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 13:07:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246224#M18424</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-06-20T13:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246275#M18425</link>
      <description>&lt;P&gt;Simple example to reproduce:&lt;/P&gt;&lt;P&gt;- Revit version: 2023&lt;/P&gt;&lt;P&gt;- Project path: "C:\Program Files\Autodesk\Revit 2023\Samples\rac_basic_sample_project.rvt"&lt;/P&gt;&lt;P&gt;- Profiling tools: JetBrains Rider, dotMemory&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var sectionType = new FilteredElementCollector(document)
    .WhereElementIsElementType()
    .OfClass(typeof(ViewFamilyType))
    .Cast&amp;lt;ViewFamilyType&amp;gt;()
    .First(x =&amp;gt; x.ViewFamily == ViewFamily.Section);

var section = ViewSection.CreateSection(document, sectionType.Id, new BoundingBoxXYZ());
section.DisplayStyle = DisplayStyle.RealisticWithEdges;

var options = new ImageExportOptions
{
    ZoomType = ZoomFitType.FitToPage,
    ExportRange = ExportRange.SetOfViews,
    FitDirection = FitDirectionType.Vertical,
    PixelSize = 220,
    ImageResolution = ImageResolution.DPI_150,
    HLRandWFViewsFileType = ImageFileType.PNG,
    ShadowViewsFileType = ImageFileType.PNG,
    FilePath = Path.GetTempPath()
};

options.SetViewsAndSheets(new List&amp;lt;ElementId&amp;gt; {section.Id});
document.ExportImage(options);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 13:45:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246275#M18425</guid>
      <dc:creator>nice3point</dc:creator>
      <dc:date>2022-06-20T13:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246311#M18426</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/824630"&gt;@jeremy_tammik&lt;/a&gt;&amp;nbsp;&amp;nbsp;Installer for versions 19-23 and the solution itself. This only happens on first run. All subsequent ones run quickly and without allocating so much memory&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 13:52:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246311#M18426</guid>
      <dc:creator>nice3point</dc:creator>
      <dc:date>2022-06-20T13:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246449#M18427</link>
      <description>&lt;P&gt;Thank you for further details and a reproducible case. From your description, I can well imagine that this behaviour is intentional. However, I submitted the ticket&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;REVIT-193325&lt;/STRONG&gt;&lt;/U&gt; [doc.ExportImage memory leak] for the developers to take a closer look.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 14:38:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246449#M18427</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-06-20T14:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246456#M18428</link>
      <description>&lt;P&gt;I don’t know whether it was intentional or not, but I don’t want them to take a couple of gigabytes of memory from me to export an 8 kilobyte image)&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 14:43:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246456#M18428</guid>
      <dc:creator>nice3point</dc:creator>
      <dc:date>2022-06-20T14:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246530#M18429</link>
      <description>&lt;P&gt;Yes, I understand. There may be other important considerations that we are unaware of. I added your comment to the ticket, anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 15:14:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246530#M18429</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-06-20T15:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246663#M18430</link>
      <description>&lt;P&gt;Do you think this is Revit causing this, or the GetFiles method indexing files looking for matches to return?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since you know the file path can't you just return it directly?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 16:12:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246663#M18430</guid>
      <dc:creator>Sean_Page</dc:creator>
      <dc:date>2022-06-20T16:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246834#M18431</link>
      <description>The breakpoint does not capture this method, and I have attached a zip archive with a solution where this method does not exist at all</description>
      <pubDate>Mon, 20 Jun 2022 17:38:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11246834#M18431</guid>
      <dc:creator>nice3point</dc:creator>
      <dc:date>2022-06-20T17:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11247336#M18432</link>
      <description>&lt;P&gt;Some objects such as ImageExportOptions, Document and UIApplication Inplement IDisposable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you tried calling Dispose on such? Ideally you should not need to but in theory GC has no knowledge of items on the unmanaged side, the dispose method is meant to be implemented to deal with those when called (also called inherently at the end of 'using' block).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although it would be a bit ridiculous calling Dispose on every API object we use so instead:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Object.Finalize should have also be overridden (or SafeHandle used) by the Autodesk API developers to deal with the unmanaged resources associated with a managed object prior to natural destruction of the managed part i.e. Finalize is always called prior to GC destroying the managed part (dispose isn't). So would assume something lacking in that area needs looking at and perhaps in meantime dispose could help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not many code samples you see would be using a 'using' block with the Document object or calling dispose after using it. So more guidance is needed in that respect if 'Dispose' is expected to be called by the developer (on which objects)? Definitely transactions that is clear but what other objects that implement IDisposable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 00:19:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11247336#M18432</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2022-06-21T00:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11248632#M18433</link>
      <description>Memory leak in the ExportImage method itself, and not when creating an object, the method returns void and I can’t influence its work in any way. Disposing ImageExportOptions does nothing</description>
      <pubDate>Tue, 21 Jun 2022 13:07:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11248632#M18433</guid>
      <dc:creator>nice3point</dc:creator>
      <dc:date>2022-06-21T13:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Memory leak when exporting images</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11270011#M18434</link>
      <description>&lt;P&gt;Analysis completed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;REVIT-193325&lt;/STRONG&gt;&lt;/U&gt; [doc.ExportImage memory leak] closed as 'code fix needed'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;REVIT-193708&lt;/STRONG&gt;&lt;/U&gt; [doc.ExportImage memory leak] raised for critical development work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for raising this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 19:20:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/memory-leak-when-exporting-images/m-p/11270011#M18434</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-06-30T19:20:39Z</dc:date>
    </item>
  </channel>
</rss>

