Theme:
v
How to repair a damaged APL+Win workspace?

Problem

It sometimes happens that an APL+Win workspace grow abnormally in size as you save it again and again. This is an indication that the workspace is somewhat damaged.

Note: this Tip applies mainly for APL+Win versions prior to v10.0 since starting at v10.0 orphans are automatically cleaned by the system on every )LOAD, )COPY and )SAVE operations.

Solution

The first step is to check if a workspace you have loaded is damaged or not. You can do this by running the following APL function:

    ∇ R←CheckWorkspace
[1]   ⍝∇ R←CheckWorkspace -- Checks the workspace for any damage
[2]   ⍝∇ If the result is a matrix of 0's, the workspace is ok
[3]   ⍝∇ If the result contains values others than 0, the workspace is damaged
[4]   ⍝∇ and may use MUCH more disk space than required
[5]   ⍝∇ Use the companion FixSystem function to repair the workspace and then )save it
[6]
[7]   R←⎕it'AuditRefcountsS'
    ∇

The result of this function should be a matrix of 0's:

      CheckWorkspace
 0 0
 0 0
 0 0

If it is not, it means your APL+Win workspace is damaged.

You can use the following APL function to repair your workspace:

    ∇ R←FixWorkspace;D;E
[1]   ⍝∇ R←FixWorkspace -- Attempts to repair the loaded damaged workspace
[2]   ⍝∇ Run function <CheckWorkspace> first: if its result contains some non 0 value(s)
[3]   ⍝∇ then run the <FixWorkspace> function once, then check again with <CheckWorkspace>
[4]   ⍝∇ Repeat these steps till the result of <CheckWorkspace> contains only 0's
[5]   ⍝∇ Then )save your workspace
[6]
[7]   R←⎕it'AuditRefcountsS'
[8]   :if 0∨.≠,R
[9]       D←0                                       ⍝ counter
[10]      :repeat
[11]          D←D+1                                 ⍝ increment counter
[12]          E←⎕it'AuditRefcountsC'                ⍝ attempts to remove ref counts problems
[13]      :until 0^.=,E                             ⍝ until no more problems
[14]      :orif D>10                                ⍝ or more than 10 iterations
[15]  :endif
[16]  R←⎕it'AuditRefcountsS'
[17]
    ∇

Additional Tip

Damaged workspaces often happen when copying an object from another already damaged workspace.

It is therefore a good idea to run the above FixWorkspace on ALL your workspaces and save them right after having run FixWorkspace