When it invoked Data_Wrap_Struct(), Ruby's GC can release allocated memory properly. However, we have to manage the memory ourselves until invoking Data_Wrap_Struct().
Check_Type() will raise an exception if the argument is not a string, and memory leak will be caused by the exception.
So, I think ALLOC() should be called after Check_Type().
You will see an increase memory usage with attached test code.
When it invoked Data_Wrap_Struct(), Ruby's GC can release allocated memory properly. However, we have to manage the memory ourselves until invoking Data_Wrap_Struct().
Check_Type() will raise an exception if the argument is not a string, and memory leak will be caused by the exception.
So, I think ALLOC() should be called after Check_Type().
You will see an increase memory usage with attached test code.
Before
After
Test code