Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Disposing of brush.ToDxBrush?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Disposing of brush.ToDxBrush?

    Code:
    RenderTarget.DrawText(
        "hello",
        textFormat,
        new SharpDX.RectangleF(100, 100, 300, 30),
        brush.ToDxBrush(RenderTarget));
    Do I need to dispose of the DX brush here? That is, should I be doing:

    Code:
    using(SharpDX.Direct2D1.Brush dxBrush = brush.ToDxBrush(RenderTarget))
    {
        RenderTarget.DrawText(
            "hello",
            textFormat,
            new SharpDX.RectangleF(100, 100, 300, 30),
            dxBrush);
    }

    #2
    Actually looks like the answer is yes since this is what is done in the VolumeZones example indicator

    Comment


      #3
      Also looks like I'll need to dispose of textFormat which is of type SharpDX.DirectWrite.TextFormat?

      Comment


        #4
        And again the answer looks like yes for textFormat as can be seen in the Ruler DrawingTools example. How expensive is creating a SharpDX.DirectWrite.TextFormat object? Should I be caching this or is it ok to create it as needed within OnRender?

        Comment


          #5
          Hello,

          It should not be too resource expensive, but just a good practice in keeping things clean to maximize performance. As to whether it is safe to instantiate them in OnRender(), that should not make much of an impact, so it should be safe to do. The exception would be cases in which someone is doing very heavy lifting with the brushes, such as creating hundreds or thousands for drawing a wide range of custom graphics on charts.
          Dave I.NinjaTrader Product Management

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kujista, Today, 06:23 AM
          3 responses
          6 views
          0 likes
          Last Post kujista
          by kujista
           
          Started by Mindset, Yesterday, 02:04 AM
          2 responses
          17 views
          0 likes
          Last Post NinjaTrader_RyanS  
          Started by f.saeidi, Today, 08:03 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by samish18, 04-17-2024, 08:57 AM
          15 responses
          52 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by f.saeidi, Today, 08:13 AM
          0 responses
          1 view
          0 likes
          Last Post f.saeidi  
          Working...
          X