Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Request: Implement System.IDisposable on SimpleFont()
Collapse
X
-
The very first example shows how I used to use Font objects, in for example, DrawText() etc.. (I know that DrawText() is NT7, and we have a new situation in NT8. I just need to know if I have to dispense with using a syntax that automatically disposes of the Font object?).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
-
Yes - 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.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
In this case, you would need to dispose of the unmanaged resources used in this objectCode: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
-
(Low priority). Is there any chance that we can get a listing of what objects will need to be Dispose()d?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
In this case, you would need to dispose of the unmanaged resources used in this objectCode: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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
670 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
379 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
111 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
582 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment