Oh and sorry to use you as a kind of living coding reference here but could you give me some idea of how to use UnLoadSeg? I take it this is the right function to use, basically the problem is, Mr Beanbag's executable is compressed in my own format, the decompression header reserves some memory, decompresses the data into it, and then jumps into it. But that leaves the compressed data still sitting in memory, uselessly. I want to be able to free it back up since it's not used anymore, but it's part of the executable.
If the compressed data occupies a section of its own then you should be able to unlink that section from the seglist and UnLoadSeg it, but I haven't actually experimented with it.
An executable is scatter-loaded into memory into a seglist, which is a singly linked list where each segment holds each section of your executable. At offset -4 of each segment you have the size of the whole segment in bytes, at 0 you have a BPTR to the next segment, or 0 if it's the last, and at 4 comes the contents of that section. If you unlink the segment with the compressed data and call UnLoadSeg on it then it should be freed correctly.
Have you looked into in-place decompression? AmigaOS supports BSS after any section, so you can have f.ex a 50K file load into the beginning of 100K of allocated space. With some margins you can decompress backwards (or move the data to the end and decompress forwards) and the decompressed data will never catch up so to speak, so any compressed data you write over has already been read in by your decompression code. This is how most compressors for executables work on the Amiga.