free_all - 1Fr3aK2/Cub3d GitHub Wiki

📝 free_all

Frees all dynamically allocated memory associated with the main t_data structure, including the map and file data. Ensures that no memory leaks occur when the program terminates or resets data.

⚙️ Parameters

Parameter Type Description
data t_data * Pointer to the main data structure containing map and file information. Can be NULL.

🔁 Returns

Return value Description
void The function does not return a value. Frees resources if data is valid.

📖 Description

The free_all function performs the following steps:

  1. Checks if the data pointer is not NULL. If it is NULL, the function returns immediately.
  2. Calls free_mlx(&data->mlx) to free MLX (graphics) resources such as windows and images.
  3. Calls free_file(&data->file) to release memory allocated for the file contents.
  4. Calls free_map(&data->map) to release memory allocated for the map structure.

This function centralizes cleanup of memory associated with the main data structure, preventing memory leaks and ensuring safe program termination.

💡 Example Usage

t_data data;

// ... code that initializes and uses data ...

// Free all allocated resources before exiting
free_all(&data);