This may be relevant to shell script writers:
Shell scripts as they are usually written now leak memory!
I'm referring to the scripts that end with:
What happens here is that the gp2x menu is launched in a subprocess. The current process (the shell executing the script) will remain in memory, waiting for the menu to terminate. This will never happen, so the shell process will remain in memory indefinitely, consuming memory (thankfully not CPU cycles).
So every time you run a script, an instance of the shell remains in memory.
Schematically:
Now, in all praticality, this may not be much of an issue. I've tested it on my machines, and it took about 200 scripts to consume enough memory that my menu wouldn't work anymore. Considering the average uptime of a GP2X, it will probably never occur that the memory is filled up in a harmful way, unless of course you're running an application that requires every last KB of memory.
I would estimate that each instance takes about 150~160KB of memory, so if you say that an average game would require about 15MB (I have no idea of realistic amounts, but this seems ample), it would require (32 - 15) / 0.16 = 106 leaking shells before the game would start to notice -- a few less if you count the memory taken up by the kernel.
As I said, this is mostly an issue of elegance, but it bears keeping in mind... seeing how the fix is very simple:
By using exec, the gp2xmenu process will now replace the shell, and the memory is returned to the system.
Shell scripts as they are usually written now leak memory!
I'm referring to the scripts that end with:
Code:
#!/bin/sh
...
cd /usr/gp2xmenu
./gp2xmenu
What happens here is that the gp2x menu is launched in a subprocess. The current process (the shell executing the script) will remain in memory, waiting for the menu to terminate. This will never happen, so the shell process will remain in memory indefinitely, consuming memory (thankfully not CPU cycles).
So every time you run a script, an instance of the shell remains in memory.
Schematically:
Now, in all praticality, this may not be much of an issue. I've tested it on my machines, and it took about 200 scripts to consume enough memory that my menu wouldn't work anymore. Considering the average uptime of a GP2X, it will probably never occur that the memory is filled up in a harmful way, unless of course you're running an application that requires every last KB of memory.
I would estimate that each instance takes about 150~160KB of memory, so if you say that an average game would require about 15MB (I have no idea of realistic amounts, but this seems ample), it would require (32 - 15) / 0.16 = 106 leaking shells before the game would start to notice -- a few less if you count the memory taken up by the kernel.
As I said, this is mostly an issue of elegance, but it bears keeping in mind... seeing how the fix is very simple:
Code:
#!/bin/sh
...
cd /usr/gp2x
exec ./gp2xmenu
By using exec, the gp2xmenu process will now replace the shell, and the memory is returned to the system.