Summary

This lesson summarizes the concepts covered in this chapter.

We'll cover the following

Chapter summary

  • The garbage collector scans the memory at unspecified times, determines the objects that cannot possibly be reached by the program, destroys them, and reclaims their memory locations.

  • The operations of the GC may be controlled by the programmer to some extent by GC.collect, GC.disable, GC.enable, GC.minimize, etc.

  • GC.calloc and other functions reserve memory, GC.realloc extends a previously allocated memory area, and GC.free returns it back to the GC.

  • It is possible to mark the allocated memory by attributes like GC.BlkAttr.NO_SCAN, GC.BlkAttr.NO_INTERIOR, etc.

  • The .alignof property is the default memory alignment of a type. Alignment must be obtained by classInstanceAlignment for class objects.

  • The .offsetof property is the number of bytes a member is from the beginning of the object that it is a part of.

  • The align attribute specifies the alignment of a variable, a user-defined type, or a member.

  • destroy() executes the destructor of objects. One must destroy the struct pointee, not the struct pointer.

  • Object.factory() constructs objects with their fully qualified type names.


Get hands-on with 1200+ tech skills courses.