Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc bug]: The PrivateFontColleciton example should have a using statement because it is unmanaged code implementing IDisposable and not disposing causes issues #1872

Open
k290 opened this issue Jul 30, 2024 · 2 comments
Assignees
Labels
doc-bug Problem with the content; needs to be fixed [org][type][category] dotnet-framework/svc help wanted Good for community contributors to help [up-for-grabs] 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

Comments

@k290
Copy link

k290 commented Jul 30, 2024

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 as PrivateFontCollection privateFontCollection = new PrivateFontCollection();

However, since it is an IDisposable with very clear cleanup code in its' own and its' base class's Dispose method surely the example should be done correctly:

using(var privateFontCollection = new PrivateFontCollection)
{


}

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 in System.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 use PrivateFontCollection

The VB code example will also need to be corrected

Page 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

@k290 k290 added doc-bug Problem with the content; needs to be fixed [org][type][category] Pri1 High priority, do before Pri2 and Pri3 labels Jul 30, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jul 30, 2024
@dotnet-policy-service dotnet-policy-service bot added the okr-health Content-health KR: Concerns article defects/freshness or build warnings. label Jul 30, 2024
@k290 k290 changed the title [doc bug]: The PrivateFontColleciton example should have a using statement because it is an IDisposable and not disposing causes issues [doc bug]: The PrivateFontColleciton example should have a using statement because it is unmanaged code implementing IDisposable and not disposing causes issues Jul 30, 2024
@adegeo
Copy link
Contributor

adegeo commented Jul 31, 2024

Thank you for reporting this. I think System.Drawing was documented with WinForms because it's the primary scenario of why it was created. I think general a lot of examples don't show using and disposing, which can be confusing.

@adegeo adegeo added dotnet-framework/svc winforms/subsvc 🗺️ reQUEST Trigger label to import an issue into Quest and removed ⌚ Not Triaged Not triaged labels Jul 31, 2024
@sequestor sequestor bot added 📌 seQUESTered Label to indicate an item has been imported. and removed 🗺️ reQUEST Trigger label to import an issue into Quest labels Aug 1, 2024
@adegeo adegeo added the help wanted Good for community contributors to help [up-for-grabs] label Aug 5, 2024
@dotnetrepoman dotnetrepoman bot added 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. and removed 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. labels Sep 23, 2024
@dotnetrepoman dotnetrepoman bot added 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. and removed 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. labels Sep 23, 2024
@adegeo adegeo removed the 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. label Sep 23, 2024
@dotnetrepoman dotnetrepoman bot added 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. and removed 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. labels Sep 23, 2024
@bigboybamo
Copy link
Contributor

Hi @adegeo I've created a PR for this #1907

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-bug Problem with the content; needs to be fixed [org][type][category] dotnet-framework/svc help wanted Good for community contributors to help [up-for-grabs] 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
Projects
Status: 🔖 Ready
Status: Slipped
Development

No branches or pull requests

4 participants