20,741
edits
mNo edit summary  | 
				|||
| Line 5: | Line 5: | ||
The mark/sweep collector is one type of garbage collector. It works by first "marking" all objects that are currently in use by the program, then "sweeping" through memory and reclaiming any objects that were not marked. This can help prevent memory leaks, but it can also cause performance issues because the mark/sweep process can be expensive in terms of computational time and can cause stuttering or non-deterministic behavior in the program.  | The mark/sweep collector is one type of garbage collector. It works by first "marking" all objects that are currently in use by the program, then "sweeping" through memory and reclaiming any objects that were not marked. This can help prevent memory leaks, but it can also cause performance issues because the mark/sweep process can be expensive in terms of computational time and can cause stuttering or non-deterministic behavior in the program.  | ||
In Nasal, arrays (vectors) and objects (also known as hashes) are implemented as a single reference, so they only count as one object for the purposes of garbage collection. This means that using arrays and objects can be efficient in terms of memory usage.  | |||
However, it is important to note that the efficiency of garbage collection depends on many factors, including the complexity of the data structures being used and the number of references that need to be searched during the mark/sweep process. If a script has a large number of complex data structures, it may still cause performance issues even if the individual objects only count as one reference each.  | |||
In terms of how loops and other control structures affect garbage collection, it is important to understand that garbage collection is a global process that cannot be restricted to a local context. When the garbage collector runs, it needs to search through all references in the program to identify which objects are no longer in use. This means that even if a particular loop or control structure does not use many references, it can still trigger the garbage collector to run and search through all references in the program.  | |||
== mark/sweep GC ==  | == mark/sweep GC ==  | ||