# Boehm garbage collector for C

**URL:** <https://community.unix.com/t/boehm-garbage-collector-for-c/371719>\
**Category:** Programming\
**Created:** [April 10, 2018, 8:30am UTC](https://community.unix.com/t/boehm-garbage-collector-for-c/371719 "2018-04-10T08:30:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dodona](https://community.unix.com/user_avatar/community.unix.com/dodona/32/2663_2.png) [@dodona](https://community.unix.com/u/dodona)\
**Post date:** [April 10, 2018, 8:30am UTC](https://community.unix.com/t/boehm-garbage-collector-for-c/371719/1 "2018-04-10T08:30:16Z")

</div>

is anybody out there experienced with the boehm gc?

this is a very simple function:

```nohighlight
 int fn1(){ 
    int *p = (int *) GC_MALLOC(sizeof(int *));   
    return 0; 
}

```

after leaving fn1() gc should free p.

\*\*\*

now another example:

```nohighlight
int* fn2(){  
    int* p= (int *) GC_MALLOC(sizeof(int *));
    return p;
 }

```

after leaving fn2() gc should not free p.

```nohighlight
int main (...){
     int* n = fn1;
     *n+=2;
     fn3(n);
     ...
}

```

my question is: does something like that work or is there any gc related function/macro for assigning a pointer to a pointer allocated by gc?

---

<div class="post-metadata">

**Author:** ![dryden](https://community.unix.com/user_avatar/community.unix.com/dryden/32/9996_2.png) [@dryden](https://community.unix.com/u/dryden)\
**Post date:** [April 22, 2018, 6:15am UTC](https://community.unix.com/t/boehm-garbage-collector-for-c/371719/2 "2018-04-22T06:15:59Z")

</div>

Sound interesting enough. Thanks for the pointer. I will make sure this pointer will not leave me when I leave this function.
