AROS Application Development Manual -- Resource Tracking
This document is not finished! It is highly likely that many parts are
out-of-date, contain incorrect information, or are simply missing
altogether. If you want to help rectify this, please contact us.
Everyone talks about Resource Tracking (RT) but what is it anyway? RT means
- The OS takes notes about allocated resources (e.g. memory, windows,
libraries, devices, screens, etc.).
- The OS checks the usage of those resources (i.e. Did you open
that window you want to render into? Is it still open? Is that a
- The OS closes resources if they are no longer used (either because your
program crashed or because it exited without freeing them).
The current implementation in AROS can do all three the things mentioned in
the Introduction, but to enable it, you must make some modifications to
your code. The only disadvantage of the current implementation is that the
resources won't be freed if the program crashes.
Add the following lines to your code. It should be the first thing
seen by the compiler:
#define ENABLE_RT 1
If you replace the 1 by 0, then RT will be silently disabled.
Add #include <aros/rt.h> after the last include from proto/
Add RT_Init(); as the first command in main().
Call RT_Exit() before you terminate your program.
The advantages are that you will get errors if you try to access resources
which you didn't allocate and that you will get a list of resources which you
didn't free at the end of your program. All messages will contain the position
in the code where the error happened (if available) and the position in the
code where the resource was allocated (this is the reason why RT has to be
compiled in. It could be built into the OS, too, but it would be hard to
gather the information where an error occurred).
A good example about how to use RT and what it can do can be found in
The following resources are tracked:
- Memory in AllocMem(), FreeMem(),``AllocVec()``, and FreeVec();
- MsgPorts in CreateMsgPort(), DeleteMsgPort(), CreatePort(),
DeletePort(), and PutMsg();
- Files in Open(), Close(), Read(), and Write(), and the
buffers of Read() and Write();
- Windows in OpenWindow(), OpenWindowTags(), OpenWindowTagList(),
CloseWindow(), WindowToFront(), and WindowToBack();
- Screens in OpenScreen(), OpenScreenTags(), OpenScreenTagList(),
CloseScreen(), ScreenToFront(), and ScreenToBack(), and windows
left open on the screen when calling CloseScreen().