[doc bug]: The PrivateFontColleciton example should have a using statement because it is unmanaged code implementing IDisposable and not disposing causes issues #1872
Labels
doc-bug
Problem with the content; needs to be fixed [org][type][category]
dotnet-framework/svc
in-pr
okr-health
Content-health KR: Concerns article defects/freshness or build warnings.
okr-quality
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Label to indicate an item has been imported.
winforms/subsvc
Type of issue
Missing information
Description
We've had a memory leak in our application and strange file-locks for a long time.
We recently found the culprit to be the
PrivateFontCollection
We found similar code in the example in the linked article. We have a suspicion we had used this article to figure out how to write the code.
In the example in the attached link
PrivateFontCollection
is instantiated asPrivateFontCollection privateFontCollection = new PrivateFontCollection();
However, since it is an
IDisposable
with very clear cleanup code in its' own and its' base class'sDispose
method surely the example should be done correctly:Given the length of the example, the indentation won't be ideal. But better to show its usage correctly than to have countless projects with unmanaged code not disposed of correctly.
Its also worth noting that although the documentation in question is filed under Winforms docs,
PrivateFontCollection
is inSystem.Drawing
and can be used in other applications. In our case we aren't using WinForms in particular, but this is the documentation that comes up when searching how to usePrivateFontCollection
The
VB
code example will also need to be correctedPage URL
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-create-a-private-font-collection?view=netframeworkdesktop-4.8#example
Content source URL
https://github.com/dotnet/docs-desktop/blob/main/dotnet-desktop-guide/framework/winforms/advanced/how-to-create-a-private-font-collection.md
Document Version Independent Id
d5c0beca-4d9c-5e2b-6869-6c50e4191402
Article author
@adegeo
Associated WorkItem - 291897
The text was updated successfully, but these errors were encountered: