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 DJ888, 04-16-2024, 06:09 PM
|
4 responses
12 views
0 likes
|
Last Post
by DJ888
Today, 04:28 PM
|
||
Started by terofs, Today, 04:18 PM
|
0 responses
8 views
0 likes
|
Last Post
by terofs
Today, 04:18 PM
|
||
Started by nandhumca, Today, 03:41 PM
|
0 responses
6 views
0 likes
|
Last Post
by nandhumca
Today, 03:41 PM
|
||
Started by The_Sec, Today, 03:37 PM
|
0 responses
3 views
0 likes
|
Last Post
by The_Sec
Today, 03:37 PM
|
||
Started by GwFutures1988, Today, 02:48 PM
|
1 response
9 views
0 likes
|
Last Post Today, 03:09 PM |
Comment