Author Topic: Bxbasic (Blunt Axe Basic)  (Read 18126 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: Bxbasic (Blunt Axe Basic)
« Reply #15 on: October 24, 2011, 01:00:41 PM »
Quote
I believe in practice you do not "NEED" to free either one as they will be freed by the os on termination of the program.

That may be true for single process applications but freeing allocated memory when using threads is recommended.

Quote from: SB Dev Docs
The major problem with memory allocation is that memory should be released. Old programs depend on the operating system to release the memory when the process exists and do not release the memory before program termination. Such programs are extremely difficult to port to multi-thread operation. In multi thread operation a thread my exit, but the memory still belongs to the process that goes on.
« Last Edit: October 24, 2011, 02:38:14 PM by JRS »

SteveA

  • Guest
Re: Bxbasic (Blunt Axe Basic)
« Reply #16 on: October 24, 2011, 02:45:23 PM »
Quote
That may be true for single process applications but freeing allocated memory when using threads is recommended.

John is correct.
You can't make assumptions about what the OS might do.
That's how memory leaks get started.

I'm not saying that Bxb is free of memory leaks, I just try to check them when I see them.
"..if you allocate memory, free it when done".

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: Bxbasic (Blunt Axe Basic)
« Reply #17 on: October 24, 2011, 03:02:40 PM »
If using C and you declare a variable within a function, the memory allocated is freed once the function is exited. I'm assuming this memory housekeeping is done by the C compiler. As Steve says, if you do a discrete allocation of memory in your program, you should free it when done and before exiting your program.

You guys are working at a much lower level and the rules under that environment are foreign to me.
 

SteveA

  • Guest
Re: Bxbasic (Blunt Axe Basic)
« Reply #18 on: October 24, 2011, 03:26:51 PM »
Quote
...if you do a discrete allocation of memory in your program, you should free it when done and before exiting your program.

Yes, the allocated memory in question is of a global nature.