Universal-Garbage-Colector

March 29, 2025 ยท View on GitHub

Universal-Garbage is a lightweight Single File C library designed to mitigate memory leak issues by providing a structured approach to memory management within scopes. It employs a garbage collection mechanism to automatically handle memory deallocation, thereby reducing the risk of memory leaks and simplifying memory management for developers.

#include "UniversalGarbageOne.c"

typedef struct Car{
   char *name;
   char *model;
}Car;

Car *newCar(char *name, char *model){
    Car *self  = (Car*)malloc(sizeof(Car));
    self->name = strdup(name);
    self->model = strdup(model);
    return self;
}
void Car_free(Car *self){
    free(self->name);
    free(self->model);
    free(self);
}
int main(){

    UniversalGarbage *garbage = newUniversalGarbage();
    Car *ferrari = newCar("ferrari","red");
    UniversalGarbage_add(garbage, Car_free,ferrari);
    printf("name %s\n",ferrari->name);
    printf("model %s\n",ferrari->model);
    UniversalGarbage_free(garbage);
}

Release

ItemDescription
UniversalGarbage.cDefinition
UniversalGarbage.hDeclaration
UniversalGarbageOne.cOne file version
UniversalGarbage.zipAll files

Documentation

ItemWhat It Is
Build and InstallInstructions for building and installing the library
Basic UsageDemonstrates the basic usage of the library with a Car object example
Add SimpleShows how to add simple types to the garbage collector
DisconnectExplains how to disconnect resources from the garbage collector
RessetDescribes resetting memory for an object
ReallocateDetails how to reallocate memory
Set ReturnExplains how to handle return values and error management

Build Toolchain