This page describes how to execute long-running console commands, to make sure they don't run out of memory.
Two examples of such commands are a custom import command and the indexing command provided by the Solr Bundle.

Disable xdebug(PHP extension to debug/profile php use) when running the command, this will cause php to use much more memory.

Memory will still grow

Even when everything is configured like described above, memory will grow for each iteration
of indexing/inserting a Content item with at least 1kb per iteration after the initial first 100 rounds.
This is expected behavior; to be able to handle more iterations you will have to do one or several of the following:

The recommended way to completely avoid "memory leaks" in PHP in the first place is to use processes.
For console scripts this is typically done using process forking which is quite easily achievable with Symfony.

The things you will need to do:

Change your command so it supports taking slice parameters, like for instance a batch size and a child-offset parameter.

If defined, child-offset parameter denotes if a process is a child,
this can be accomplished using two commands as well.

If not defined, it is the master process which will execute the processes until nothing is left to process.

Change the command so that the master process takes care of forking child processes in slices.