igraph Reference Manual

For using the igraph C library

Chapter 6. Memory (de)allocation

1. igraph_free — Deallocate memory that was allocated by igraph functions

int igraph_free(void *p);

Some igraph functions return a pointer vector (igraph_vector_ptr_t) containing pointers to other igraph or other data types. These data types are dynamically allocated and have to be deallocated manually, if the user does not need them any more. This can be done by calling igraph_free on them.

Here is a complete example on how to use igraph_free properly.

#include <igraph.h>

int main(void)
{
   igraph_t graph;
   igraph_vector_ptr_t seps;
   long int i;

   igraph_famous(&graph, "tutte");
   igraph_vector_ptr_init(&seps, 0);
   igraph_minimum_size_separators(&graph, &seps);
   
   for (i=0; i<igraph_vector_ptr_size(&seps); i++) {
     igraph_vector_t *v=VECTOR(seps)[i];
     igraph_vector_print(v);
     igraph_vector_destroy(v);
     igraph_free(v);
   }

   igraph_vector_ptr_destroy(&seps);
   igraph_destroy(&graph);
   return 0;
}

Arguments: 

p:

Pointer to the piece of memory to be deallocated.

Returns: 

Error code, currently always zero, meaning success.

Time complexity: platform dependent, ideally it should be O(1).