MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
| 2 | void destruct(object ob) |
| 3 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 4 | DESCRIPTION |
| 5 | Completely destroy and remove object ob (if not already done so). |
| 6 | After the call to destruct(), no global variables will exist any |
| 7 | longer, only local ones, and arguments. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 8 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 9 | If an object self-destructs, it will not immediately terminate |
| 10 | execution. If the efun this_object() will be called by the |
| 11 | destructed object, the result will be 0. Furthermore, all |
| 12 | calls to other objects and to simul-efuns will be ignored, instead |
| 13 | the driver will return 0 als 'call' result. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 14 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 15 | To keep things consistent, most mudlibs frown upon the |
| 16 | destruct()ion of other objects, and instead demand call_others |
| 17 | to a specific lfun in the object to destruct (traditionally |
| 18 | named "remove"). This will then ensure correct update of e.g. |
| 19 | weights, volumes etc. Additionally or instead, the master apply |
| 20 | prepare_destruct() can be used for this 'cleanup' functionality. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 21 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 22 | The interpreter does not really destruct the object |
| 23 | immediately, but marks it as deleted, removes it from the list |
| 24 | of all objects, and puts it onto a list of to-be-destructed |
| 25 | objects. The actual freeing occurs only when all references to |
| 26 | a destructed object have gone. Thus it is possible, that an |
| 27 | object occupies memory long after it has been destructed, |
| 28 | although the object is not visible anywhere anymore from |
| 29 | outside. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 30 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 31 | EXAMPLES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 32 | ob->remove(); |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 33 | if(ob) /* still there, probably ob does not provide remove() */ |
| 34 | destruct(ob); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 35 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 36 | This is a way of destructing an object but giving it a chance |
| 37 | to do it by itself. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 38 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 39 | HISTORY |
| 40 | Changed in 3.2.7 to accept destructed objects as argument, too. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 41 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 42 | SEE ALSO |
| 43 | clone_object(E), remove(A), prepare_destruct(M) |