Contents | < Browse | Browse >
5M. memory deallocation (END)
-----------------------------
END is the complement to NEW. any pointer obtained should be
deallocated (and only!) with END

	END a

or even

	END a,b,c

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

	END a[NUM]

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
for classes.

You can imagine END p as a macro for:

	IF p
	  p.end()
	  FastDispose(p,p.classobject.virtuallen)
	  p:=NIL
	ENDIF

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).