You can use $result->free_result() to free the results, but sometimes this isn’t the root cause of excessive memory usage. Also, some calls (such as INSERTs) do not return a database object, so you can’t free() them. With very many INSERTs this can really bite you, as CI defaults to saving all your queries.
An undocumented CI feature is available to turn this off:
$this->db->save_queries = false;
There may be performance (caching) issues associated with disabling this across the board - ie. caution and experimentation is indicated.