Definition of space complexity when algorithm cycles.
So how does one measure the space complexity of an algorithm that may cycle forever?


When we say that some language $L$ belongs to some complexity class it is assumed that a TM (algorithm) decides $x \in L$ in finite space and time amount. In other words, the TM/algorithm terminates, i.e. it may not cycle forever. However, an algorithm that loops forever may use finite space,  but it still cannot decide.

But I don't understand the following statement


  In an algorithm where space is counted, there can exist computations that never end, but one can always transform the algorithm into another that doesn't cycle.