Do variables need to be freed?
-
Now that variables have arrived (I'll have to wait till the weekend to play), I was just wondering if there might be any "gotchas" with regards to memory allocation.
So a few questions- Are there likely to be any memory issues on Duet2 or other boards that are close to the limit?
- Are local variables automatically freed at the end of a macro or print file?
- In the case of global variables, what happens if for example M98 P"0:/config.sys" is run and it contains global variables?
- Any other areas to consider?
-
@OwenD said in Do variables need to be freed?:
- Are there likely to be any memory issues on Duet2 or other boards that are close to the limit?
Yes if you create a lot of variables, especially variables with string values. Most likely to be an issue on Duet WiFi/Ethernet with 12864 display configured. M122 displays a new Heap status line in the Platform section, which shows how much string heap is being used.
- Are local variables automatically freed at the end of a macro or print file?
Yes.
- In the case of global variables, what happens if for example M98 P"0:/config.sys" is run and it contains global variables?
You will get an error message for each one, because the variable is already defined.
- Any other areas to consider?
None that I can think of.
-
@dc42 said in Do variables need to be freed?:
@OwenD said in Do variables need to be freed?:
Are there likely to be any memory issues on Duet2 or other boards that are close to the limit?
Yes if you create a lot of variables, especially variables with string values. Most likely to be an issue on Duet WiFi/Ethernet with 12864 display configured. M122 displays a new Heap status line in the Platform section, which shows how much string heap is being used.
I just compared the M122 output of my Duet2 (w/o LCD) and the Maestro (with 12864 LCD) and I couldn't find a difference in the Platform/Heap line?
Heap OK, handles allocated/used 0/0, heap memory allocated/used/recyclable 0/0/0, gc cycles 0
I also saw Platform/available RAM. Is that the max. memory we can play with in Meta-code macros?
-
The values will change as you add variables to the heap.
These are three outputs on my printer after adding additional variables
(Duet 2 wifi with PanelDue 7i)Heap OK, handles allocated/used 99/9, heap memory allocated/used/recyclable 2048/994/870, gc cycles 21 Heap OK, handles allocated/used 99/11, heap memory allocated/used/recyclable 2048/1150/1010, gc cycles 21 Heap OK, handles allocated/used 99/13, heap memory allocated/used/recyclable 2048/1312/1150, gc cycles 21
-
@owend
Then the 12864 LCD only eats Duet2 memory, because it's not natively supported, as it is by Maestro? -
@o_lampe said in Do variables need to be freed?:
@owend
Then the 12864 LCD only eats Duet2 memory, because it's not natively supported, as it is by Maestro?The 12864 LCD eats memory on any Duet now, however the Maestro has more free memory available to start with.