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:
- Checks if the
datapointer is notNULL. If it isNULL, the function returns immediately. - Calls
free_mlx(&data->mlx)to free MLX (graphics) resources such as windows and images. - Calls
free_file(&data->file)to release memory allocated for the file contents. - 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);