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 iceman2018, Today, 05:07 PM
          0 responses
          4 views
          0 likes
          Last Post iceman2018  
          Started by rhyminkevin, Today, 04:58 PM
          0 responses
          23 views
          0 likes
          Last Post rhyminkevin  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          6 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          49 views
          0 likes
          Last Post futtrader  
          Working...
          X