Contents | < Browse | Browse >
5M. memory deallocation (END)
END is the complement to NEW. any pointer obtained should be
deallocated (and only!) with END
where the arguments are PTRs to some type. END frees the amount of space
that is being pointed to, so if a is PTR TO LONG it will only free 4
bytes. so if you allocated a with NEW a[NUM], free it with
NIL-pointers may safely be passed to NEW. Pointers are also
nuked to NIL afterwards.
If a is a PTR to an object that is an instance of a class, END
will dynamically get the size to be freed from the class-object,
so if you have an object of class b which is 32 bytes, but the
pointer you're freeing with is a baseclass pointer (only 24
bytes), END will correctly deallocate 32 bytes. this only works
You can imagine END p as a macro for:
If you don't call END on memory allocated by NEW, it will be deallocated
automatically at the end of the program, however no destructor methods
(.end()) will be called at this stage (i.e. if this is necessary you'll have
to do it yourself).
note that the NEW and END make use of the FastNew() and FastDispose()
functions (described elsewhere) which work quite differently from
NewR() and Dispose(). (see 9F for details).