GLib.Array.set_clear_func
Description: Reference for GLib.Array.set_clear_func

### Function

# GLib Arrayset_clear_func

since: 2.32

#### Declaration [src]

    void
    g_array_set_clear_func (
      GArray* array,
      GDestroyNotify clear_func
    )

#### Description [src]

Sets a function to clear an element of `array`.

The `clear_func` will be called when an element in the array data segment is removed and when the array is freed and data segment is deallocated as well. `clear_func` will be passed a pointer to the element to clear, rather than the element itself.

Note that in contrast with other uses of `GDestroyNotify` functions, `clear_func` is expected to clear the contents of the array element it is given, but not free the element itself.

    typedef struct
    {
      gchar *str;
      GObject *obj;
    } ArrayElement;

    static void
    array_element_clear (ArrayElement *element)
    {
      g_clear_pointer (&element->str, g_free);
      g_clear_object (&element->obj);
    }

    // main code
    GArray *garray = g_array_new (FALSE, FALSE, sizeof (ArrayElement));
    g_array_set_clear_func (garray, (GDestroyNotify) array_element_clear);
    // assign data to the structure
    g_array_free (garray, TRUE);

Available since: 2.32

This function is not directly available to language bindings.

#### Parameters

`array`

  Type: An array of `gpointer`

  A `GArray`.

  The data is owned by the caller of the function.

`clear_func`

  Type: `GDestroyNotify`

  A function to clear an element of `array`.