To have no memory leak, there is a better solution , there is a lot of
language designed to avoid them. Did you already try Pyhon or Ruby?
The best solution is to allocate memory only at start-up or avoid it at
all. If one uses depth-first-search, the memory-usage is proportional to
the maximum search depth. This can be easily allocated in a fixed-size
array at compile time. One only needs to allocate the Hashtable at
startup.
As Aske Plaat has shown are breadth-first search methods identical to
Depth-First-Methods augmented with Hashtables. There is in my opinion no
reason to use breadth first search.
Maybe there is in Go - besides breadth-first-search - another place where
one needs dynamic-memory-allocation. If yes, I would be interested for which
parts dynamic memory is needed.
Chrilly Donninger