Code cleanup refers to the act of writing so that it cleans up leftover and other unwanted materials from memory and the filesystem. It is sometimes treated as a synonym of refactoring code, which involves making the source code itself easier to understand, maintain, and modify.[1]
In C++, code cleanup involves deallocating previously allocated dynamic memory.
This is usually done with the C++ delete
and delete[]
operations.[2]
In Python 3, explicit deletion of variables requires the del
keyword.[3]
In JavaScript, objects are garbage collected if they are unreachable from the global object.[4] One way to make an object unreachable is to overwrite the variables or properties that reference it.
In Java, variables cannot be truly deleted. The most that can be done is to set the variable to null
, which works with any Java object, including arrays.[5]
Code cleanup can also refer to the removal of all computer programming from source code, or the act of removing temporary files after a program has finished executing.
For instance, in a web browser such as Chrome browser or Maxthon, code must be written in order to clean up files such as cookies and storage.[6] The deletion of temporary files is similar to the deletion of unneeded lists and arrays of data. However, a file is treated as a permanent way to store a resizable list of bytes, and can also be removed from existence.[7]
Another technical term sometimes called "code cleanup" is loop cleanup.
import typelist = [10, 20, 30, 40, 50]/* 'Even in a for each loop, code cleanup with an incremented variable is still needed.' */i = 0for each element of list list[i] ^= 2 // 'Squares the element.' print string(element) + " is now... " + string(list[i]) i++end