I understand what you are saying, GDK returns int values for many of their functions - you don't need to worry about those. However, when returning a pointer; that's the problem.
Internally (inside the compiler), when returning an int, the result is pushed into a CPU register (typically EAX [or derivative depending on what processor I suppose]). When the function returns, the calling function pop's that value from the CPU register. Therefore, the calling function is responsible for allocation/deallocation of the memory (the compiler handles this for you).
However, when returning a pointer - as in char*, the memory must be allocated on the heap (physical memory somewhere) and the address of that location is returned via the EAX register. Since that chunk of memory is flagged as in use by the OS, no future allocations can touch it until it is un-flagged. And since the GDK doesn't know what you will be doing with that memory location, it can't just simply delete it - you have to be the one to tell the OS that you're done with it.
Now, it may appear to you that this is only a problem when GDK returns a char* but in fact, it would be a problem if the GDK returned an int*, float* or whatever other pointer type you could think of.
Q: What about returning a reference&? Isn't that the same thing?
A: Well, yes and no. Yes, a reference is effectively an address to a spot in memory. But, when used in conjunction with a variable declared internally to a function, it will (via details handled by the compiler) be invalid since the compiler will allocate and release that memory from the OS without you - the programmer - having to worry about those details.
Therefore...
char* foo(void) {
char str[20];
return &str;
}
In the above code snippet, the compiler is performing the memory allocation for you; it requests 20-bytes of memory from the OS, which the OS flags as being used. Once you execute the return statement, code injected by the compiler effectively informs the OS that you are done using it...
To get around this, the GDK will specifically inform the OS itself that the memory is needed:
char* foo(void) {
char* result = new char[20];
return result;
Whenever you call the operator new(), you must remember to call the operator delete() in order to free up the memory. The compiler didn't call the operator new() in this case, you the programmer did. Therefore, you (the programmer) are responsible for calling delete().
Of course, TGC is very aware of these differences in return types and for whatever reason, they have designed their GDK in such a way as to effectively say: if you ask for it, *you* own it! I can't say for sure, but I would guess that the reason for this decision is in support of the DarkBasic product (from which GDK originated)...
I hope this helps explain things a little better for you,
JTK