Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Request: Implement System.IDisposable on SimpleFont()
Collapse
X
-
Originally posted by NinjaTrader_Matthew View PostThe SimpleFont uses complete managed .NET resources so they should be managed by the GC.
Our developers are curious why you feel you would need to dispose of these objects? Are you seeing instances where references are being held on to?
ref: https://msdn.microsoft.com/en-us/library/yh598w02.aspx
Are we saying that for SimpleFont, this statement about managed types accessing unmanaged resources, such as device contexts does not apply?
File and Font are examples of managed types that access unmanaged resources (in this case file handles and device contexts). There are many other kinds of unmanaged resources and class library types that encapsulate them. All such types must implement the IDisposable interface.
Comment
-
Originally posted by koganam View PostAre we saying that for SimpleFont, this statement about managed types accessing unmanaged resources, such as device contexts does not apply?
Objects like Font which wrap unmanaged resources do need to be disposed of as the GC is not aware of them. However SimpleFont does not use the Font class referenced in that MSDN article, therefore you do not need to dispense these SimpleFont objects for something like Draw.Text()
The exception would be if you're using your own SharpDX.TextFormat from a SimpleFont
Code:SharpDX.DirectWrite.TextFormat textFormat = myFont.ToDirectWriteTextFormat();
Code:NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12); using (SharpDX.DirectWrite.TextFormat textFormat = myFont.ToDirectWriteTextFormat()) { textFormat.FlowDirection = SharpDX.DirectWrite.FlowDirection.TopToBottom; }
Last edited by NinjaTrader_Matthew; 06-08-2015, 03:44 PM.MatthewNinjaTrader Product Management
Comment
-
Originally posted by NinjaTrader_Matthew View PostYes - All of the objects used in SimpleFont are managed, therefore they will be picked up by the garbage collector. There should be no reason to need to dispose of a managed resource.
Objects like Font which wrap unmanaged resources do need to be disposed of as the GC is not aware of them. However SimpleFont does not use the Font class referenced in that MSDN article, therefore you do not need to dispense these SimpleFont objects for something like Draw.Text()
The exception would be if you're using your own SharpDX.TextFormat from a SimpleFont
Code:SharpDX.DirectWrite.TextFormat textFormat = myFont.ToDirectWriteTextFormat();
Code:NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12); using (SharpDX.DirectWrite.TextFormat textFormat = myFont.ToDirectWriteTextFormat()) { textFormat.FlowDirection = SharpDX.DirectWrite.FlowDirection.TopToBottom; }
Comment
-
Yes, we can provide that in the documentation.
From the top of my head, common objects you would need to dispose of include:
- NinjaTrader.Gui.Stroke
- SharpDX.Direct2D1.Brush
- SharpDX.DirectWrite.TextLayout
- SharpDX.DirectWrite.TextFormat
- SharpDX.Direct2D1.PathGeometry
There are others in the SharpDX library that you may come across (bitmaps, etc), but these are the most common objects you'll come across for general chart rendering.MatthewNinjaTrader Product Management
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by wzgy0920, 04-20-2024, 06:09 PM
|
2 responses
27 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:43 PM
|
||
Started by wzgy0920, 02-22-2024, 01:11 AM
|
5 responses
32 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:33 PM
|
||
Started by wzgy0920, 04-23-2024, 09:53 PM
|
2 responses
49 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:29 PM
|
||
Started by Kensonprib, 04-28-2021, 10:11 AM
|
5 responses
193 views
0 likes
|
Last Post
by Hasadafa
Yesterday, 10:19 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
11 responses
3,235 views
0 likes
|
Last Post Yesterday, 08:07 PM |
Comment