# Memory marking problem

**URL:** <https://www.ruby-forum.com/t/memory-marking-problem/101401>\
**Category:** Ruby\
**Created:** [August 4, 2006, 5:52pm UTC](https://www.ruby-forum.com/t/memory-marking-problem/101401 "2006-08-04T17:52:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [August 4, 2006, 5:52pm UTC](https://www.ruby-forum.com/t/memory-marking-problem/101401/1 "2006-08-04T17:52:53Z")

</div>

I’m pretty new to Ruby and running into some odd issues with my “mark”  
function. Basically I have a situation like this

```auto
void ruby_node_free( void* ptr ){
   delete reinterpret_cast<Node*>( ptr );
}
void ruby_node_mark( VALUE self ){
  Node* ptr = reinterpret_cast<Node*>(DATA_PTR(self));
  if( ptr ){
    // these are all ruby arrays
    rb_gc_mark( ptr->verts );
    rb_gc_mark( ptr->normals );
    rb_gc_mark( ptr->uvw );
  }
}
void ruby_node_alloc( VALUE klass ){
  Node* ptr = new Node;
  VALUE object = Data_Wrap_Struct( klass, ruby_node_mark, 
ruby_node_free, ptr );
  return( object );
}
```

What happens is when my ruby\_node\_mark function is called and I grab the  
Node\* that value is some chode memory value like 0xfdfdfdfd. I’m  
wondering if anyone has run into any problems like this where it seems  
that some variables are being deleted twice or something like that.

---

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [August 4, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/memory-marking-problem/101401/2 "2006-08-04T18:06:40Z")

</div>

> > > > > “J” == Joe B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

J\> void ruby\_node\_free( void\* ptr ){  
J\> delete reinterpret\_cast\<Node\*\>( ptr );  
J\> }  
J\> void ruby\_node\_mark( VALUE self ){  
J\> Node\* ptr = reinterpret\_cast\<Node\*\>(DATA\_PTR(self));

The mark function take the same argument than the free function, void  
\*ptr  
in your case.

Guy Decoux

---

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [August 4, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/memory-marking-problem/101401/3 "2006-08-04T18:41:11Z")

</div>

ts wrote:

> > > > > > “J” == Joe B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> J\> void ruby\_node\_free( void\* ptr ){  
> J\> delete reinterpret\_cast\<Node\*\>( ptr );  
> J\> }  
> J\> void ruby\_node\_mark( VALUE self ){  
> J\> Node\* ptr = reinterpret\_cast\<Node\*\>(DATA\_PTR(self));
> 
> The mark function take the same argument than the free function, void  
> \*ptr  
> in your case.
> 
> Guy Decoux

Thanks - that was it - I don’t know how I managed to breeze by that  
glaring error =) Thank you!

Joe
