20,741
edits
mNo edit summary  | 
				m (→mark/sweep GC)  | 
				||
| Line 10: | Line 10: | ||
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.  | 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.  | ||
== memory management ==  | |||
In the programming language Nasal, variables do not point to garbage. Instead, the objects that they reference are garbage. This means that when the garbage collector runs, it only needs to search through the objects being pointed to by variables, rather than the variables themselves. Additionally, scalar values such as numbers are not treated as references in Nasal and are stored directly in the hash record, rather than being pointed to by a reference.  | |||
The "var" syntax in Nasal has no effect on allocation and is only used for scoping. This means that it defines a local variable within the current function, regardless of any outer scope it may be in.  | |||
There are several operations in Nasal that create heap blocks or garbage, including string composition with the "~" operator, vector creation with a "[...]" expression, hash creation with a "{...}" expression, function calls, and closure binding with a "func ..." expression. These operations can create objects that are eligible for garbage collection and should be used carefully to avoid performance issues.  | |||
Thus, the primary operations in Nasal that create heap blocks/garbage are:  | |||
* String composition with the "~" operator  | |||
* Vector creation with a "[...]" expression  | |||
* Hash creation with a "{...}" expression  | |||
* Function calls (which create a hash for the namespace)  | |||
* Closure binding with a "func ..." expression.  | |||
== mark/sweep GC ==  | == mark/sweep GC ==  | ||