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 jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,290 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          9 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          11 responses
          62 views
          0 likes
          Last Post halgo_boulder  
          Started by Option Whisperer, Today, 09:55 AM
          0 responses
          8 views
          0 likes
          Last Post Option Whisperer  
          Started by halgo_boulder, 04-20-2024, 08:44 AM
          2 responses
          25 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X