GC Types
Reference counting
COM for example had AddRef and Release cals for objects
When count hits zero => object can be freed
Problems with circular references
Mark and sweep
Mark phase - identify objects that are still in use
Sweep phase - remove unused objects
Compact phase - compact the memory
![](https://amartyushov.gitbook.io/~gitbook/image?url=https%3A%2F%2F415484505-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LxtoAXZwwOc4XGto8vb%252Fuploads%252FiBSjfdr1CzRCCYDRewAu%252FScreenshot%25202023-12-19%2520at%252009.03.15.png%3Falt%3Dmedia%26token%3Dd78e9880-85be-4c27-87ab-c8af2cf3e5ef&width=768&dpr=4&quality=100&sign=d9df8da3&sv=1)
We follow references from root set. If two objects are referencing each other, but non of them is referenced by root set => these objects will not be marked as actually used (this is how cycle problem is solved).
![](https://amartyushov.gitbook.io/~gitbook/image?url=https%3A%2F%2F415484505-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LxtoAXZwwOc4XGto8vb%252Fuploads%252FB6JrAgmGJafSQ7EIsUn0%252FScreenshot%25202023-12-19%2520at%252009.06.00.png%3Falt%3Dmedia%26token%3Dc88794d1-22b2-473c-b45f-6f66575330c7&width=768&dpr=4&quality=100&sign=82661b16&sv=1)
![](https://amartyushov.gitbook.io/~gitbook/image?url=https%3A%2F%2F415484505-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LxtoAXZwwOc4XGto8vb%252Fuploads%252FDRh7hbAYLmf1OJPRl7R9%252FScreenshot%25202023-12-19%2520at%252009.06.30.png%3Falt%3Dmedia%26token%3D5c321ee7-2727-4819-bf84-4cbaf48fa3aa&width=768&dpr=4&quality=100&sign=9f024e23&sv=1)
Copying
Uses different spaces
to manage memory. It also has Mark and Sweep phases.
![](https://amartyushov.gitbook.io/~gitbook/image?url=https%3A%2F%2F415484505-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LxtoAXZwwOc4XGto8vb%252Fuploads%252FteH6xSIyFA4uS8hXf2GY%252FScreenshot%25202023-12-19%2520at%252009.11.03.png%3Falt%3Dmedia%26token%3D8d4ddfa8-c225-4cec-928d-7e379afe34ad&width=768&dpr=4&quality=100&sign=fafdb779&sv=1)
![](https://amartyushov.gitbook.io/~gitbook/image?url=https%3A%2F%2F415484505-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LxtoAXZwwOc4XGto8vb%252Fuploads%252FX8VGcP8MtpFPCsAYNtOx%252FScreenshot%25202023-12-19%2520at%252009.11.50.png%3Falt%3Dmedia%26token%3D851ca9e8-e5ed-4f6d-950c-dc6d25b89156&width=768&dpr=4&quality=100&sign=53145b15&sv=1)
Generational
Maintain different generations for memory. Long living objects promoted to a different generation.
![](https://amartyushov.gitbook.io/~gitbook/image?url=https%3A%2F%2F415484505-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LxtoAXZwwOc4XGto8vb%252Fuploads%252FNcHhhaanY2wyBlRzpIWn%252FScreenshot%25202023-12-19%2520at%252009.15.01.png%3Falt%3Dmedia%26token%3D5017c58e-0e8c-4311-9a74-6a468fb642b6&width=768&dpr=4&quality=100&sign=95cc9835&sv=1)
![](https://amartyushov.gitbook.io/~gitbook/image?url=https%3A%2F%2F415484505-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LxtoAXZwwOc4XGto8vb%252Fuploads%252FR2zuUnRpxTJ5njdki6Dx%252FScreenshot%25202023-12-19%2520at%252009.15.29.png%3Falt%3Dmedia%26token%3D245c6e90-a2b1-4e87-af8c-c56a7c91f248&width=768&dpr=4&quality=100&sign=a70cb82&sv=1)
Last updated