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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          657 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          373 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          579 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X