FreeBrush

Syntax

Success = FreeBrush(Brush)

Description

Releases the resources associated with the specified brush object. After calling this function, the brush handle is no longer valid and should not be used.

Parameters

Brush
The handle of the brush object to free. This handle should have been obtained from a `CreateBrush...` function.

Return Value

Returns #True if the brush was successfully freed, or #False if the handle was invalid.

Remarks

It is important to free all created brushes when they are no longer needed to avoid memory leaks and release graphics resources. If the brush was an image brush, freeing the brush also decrements the reference count of the associated image (FreeImg may be called implicitly if the count reaches zero).

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

MyImage = CreateImg(50, 50)
MyGradient = CreateBrushGradientLinear(0, 0, 100, 100, #Red, 1.0, #Blue, 1.0)
MyImageBrush = CreateBrushImg(MyImage)

; ... use the brushes ...

If MyGradient
  FreeBrush(MyGradient) ; Free the gradient brush
  MyGradient = #Null ; Good practice to nullify the handle
  Debug "Gradient Brush Freed."
EndIf

If MyImageBrush
  FreeBrush(MyImageBrush) ; Free the image brush
  MyImageBrush = #Null
  Debug "Image Brush Freed."
EndIf

If MyImage
  FreeImg(MyImage) ; Free the image itself
  MyImage = #Null
  Debug "Image Freed."
EndIf

StopProGUI()

See Also

CreateBrushImg, CreateBrushGradientLinear, CreateBrushGradientRadial, FreeImg

Supported OS

Windows, Linux