We’re declaring quite a few variables within update (other functions called by it). The various speed floats are probably not too impactful. My main concerns are the rotationVector and inputMoveDir. We’re creating two new vector3s every frame. If the game were running long enough, would that cause problems? Does the old one get deleted, or is there some kind of caching despite it being “new”?
Variables declared in a function are only scoped to that function. Once the update is complete, they are no longer referenced and the memory is reclaimed. This is true for Vectors and such. Some classes may do more under the hood that requires ‘cleanup’, but if that’s the case the lecture will almost surely state that and act accordingly.
Some classes will implement an IDisposable
interface. These require you to clean them up when you are done by calling the Dispose()
method on them, or using them in a using
clause, which will dispose it when the clause ends. Vectors and Quaternions and such, are structs and do not require cleaning up
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.