-
What are the pros and cons of using the Garbage Collector in nelua? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Well, the garbage collector makes life easier when prototyping code quickly, because you don't need to care about cleaning memory allocations when it's not used anymore, it also may protect you from programming mistakes because manual memory management can be difficult and it is common to make mistakes. However, the payoff is runtime cost in terms of efficiency and memory, because the program may pause a while to scan the whole memory for references that are not referenced anymore (to free its memory). Here are some lists of advantages and disadvantages, though this topic is popular and you can also research on the web: Advantages of using GC:
Disadvantages of using GC:
Here I will also list some common mistakes when doing manual memory management and not using the GC:
Where using GC can be recommended:
Where using the GC is not recommended:
For me the biggest advantage is that we can prototype code fast, in case we want to optimize we can always upgrade the code later by adding cleanup routines, or maybe we don't even need to because things may be efficient enough already. I typically use the GC when prototyping new stuff. |
Beta Was this translation helpful? Give feedback.
Well, the garbage collector makes life easier when prototyping code quickly, because you don't need to care about cleaning memory allocations when it's not used anymore, it also may protect you from programming mistakes because manual memory management can be difficult and it is common to make mistakes. However, the payoff is runtime cost in terms of efficiency and memory, because the program may pause a while to scan the whole memory for references that are not referenced anymore (to free its memory). Here are some lists of advantages and disadvantages, though this topic is popular and you can also research on the web:
Advantages of using GC: