Code segment unload: Difference between revisions

Content added Content deleted
m (omit from assembly)
m (syntax highlighting fixup automation)
Line 8: Line 8:
=={{header|BASIC}}==
=={{header|BASIC}}==
Some versions of basic have the facility to delete lines of code:
Some versions of basic have the facility to delete lines of code:
<lang gwbasic>10 GOSUB 5000: REM call initializer
<syntaxhighlight lang="gwbasic">10 GOSUB 5000: REM call initializer
20 DELETE 5000-9999: REM delete initializer
20 DELETE 5000-9999: REM delete initializer
30 PRINT A: REM show initializer worked
30 PRINT A: REM show initializer worked
Line 16: Line 16:
5000 REM this is a dummy initializer
5000 REM this is a dummy initializer
5010 LET A=1
5010 LET A=1
5020 RETURN</lang>
5020 RETURN</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
The <code>CANCEL</code> statement in COBOL unloads from memory the dynamically-loadable module containing the specified program or entry-point.
The <code>CANCEL</code> statement in COBOL unloads from memory the dynamically-loadable module containing the specified program or entry-point.
<lang cobol>CANCEL "foo"</lang>
<syntaxhighlight lang="cobol">CANCEL "foo"</syntaxhighlight>


=={{header|Furor}}==
=={{header|Furor}}==
The <code>neglect</code> statement in Furor deletes from memory the named function. It is possible because each function is loaded into a dinamycally allocated memory segment.
The <code>neglect</code> statement in Furor deletes from memory the named function. It is possible because each function is loaded into a dinamycally allocated memory segment.
<lang Furor>foo neglect</lang>
<syntaxhighlight lang="Furor">foo neglect</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 32: Line 32:


=={{header|Io}}==
=={{header|Io}}==
<lang Io># Call anonymous block to do the initialization.
<syntaxhighlight lang="Io"># Call anonymous block to do the initialization.


block(
block(
Line 42: Line 42:


writeln("Doing real work.")
writeln("Doing real work.")
// Code to do the real work here.</lang>
// Code to do the real work here.</syntaxhighlight>


{{output}}
{{output}}
Line 113: Line 113:
;Releasing commands
;Releasing commands
:The memory associated with a particular command can be released back to the general memory pool by deleting the command. This is done by either creating a new command with the same name, or by using <code>rename</code> to change the command's name to the empty string.
:The memory associated with a particular command can be released back to the general memory pool by deleting the command. This is done by either creating a new command with the same name, or by using <code>rename</code> to change the command's name to the empty string.
:<lang tcl>rename exampleCmd ""</lang>
:<syntaxhighlight lang="tcl">rename exampleCmd ""</syntaxhighlight>
;Releasing loaded extensions
;Releasing loaded extensions
:The memory associated with a loaded extension can be released by using <code>unload</code>, provided the extension has registered a handler function (this is relatively uncommon). Once the handler function has run (which gives the extension an opportunity to destroy any commands and other callbacks it has created), the underlying library will be removed from memory with <code>dlclose()</code> (on Unix) or <code>FreeLibrary()</code> (on Windows). This ''completely'' removes the program code concerned, as well as returning the other ancillary memory to the general pool.
:The memory associated with a loaded extension can be released by using <code>unload</code>, provided the extension has registered a handler function (this is relatively uncommon). Once the handler function has run (which gives the extension an opportunity to destroy any commands and other callbacks it has created), the underlying library will be removed from memory with <code>dlclose()</code> (on Unix) or <code>FreeLibrary()</code> (on Windows). This ''completely'' removes the program code concerned, as well as returning the other ancillary memory to the general pool.
:<lang tcl>unload theLibrary.dll</lang>
:<syntaxhighlight lang="tcl">unload theLibrary.dll</syntaxhighlight>
;Releasing an entire interpreter
;Releasing an entire interpreter
:Provided an interpreter is not the ''root'' interpreter in its thread, you can delete it from an ancestor interpreter, which releases all the memory associated with it back into the general memory pool.
:Provided an interpreter is not the ''root'' interpreter in its thread, you can delete it from an ancestor interpreter, which releases all the memory associated with it back into the general memory pool.
:<lang tcl>interp delete theChildInterpreter</lang>
:<syntaxhighlight lang="tcl">interp delete theChildInterpreter</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==