Skip to content
Snippets Groups Projects
Commit 162f5bdd authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Prevent TracePoint objects from being GC'd

By just stuffing these into the Allocations module as a constant we can
prevent them from being GC'd.
parent f671a853
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -126,12 +126,6 @@ VALUE allocations_start(VALUE self) {
 
rb_mutex_unlock(mutex);
 
allocation_tracer = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_NEWOBJ,
newobj_callback, NULL);
free_tracer = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_FREEOBJ,
freeobj_callback, NULL);
rb_tracepoint_enable(allocation_tracer);
rb_tracepoint_enable(free_tracer);
 
Loading
Loading
@@ -153,10 +147,8 @@ VALUE allocations_stop(VALUE self) {
return Qnil;
}
 
if ( allocation_tracer && free_tracer ) {
rb_tracepoint_disable(allocation_tracer);
rb_tracepoint_disable(free_tracer);
}
rb_tracepoint_disable(allocation_tracer);
rb_tracepoint_disable(free_tracer);
 
if ( object_counts ) {
st_free_table(object_counts);
Loading
Loading
@@ -194,6 +186,12 @@ VALUE allocations_enabled_p(VALUE self) {
void Init_liballocations() {
VALUE mAllocations = rb_define_module_under(rb_cObject, "Allocations");
 
allocation_tracer = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_NEWOBJ,
newobj_callback, NULL);
free_tracer = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_FREEOBJ,
freeobj_callback, NULL);
mutex = rb_mutex_new();
 
id_enabled = rb_intern("enabled");
Loading
Loading
@@ -204,4 +202,6 @@ void Init_liballocations() {
rb_define_singleton_method(mAllocations, "enabled?", allocations_enabled_p, 0);
 
rb_define_const(mAllocations, "MUTEX", mutex);
rb_define_const(mAllocations, "ALLOCATION_TRACER", allocation_tracer);
rb_define_const(mAllocations, "FREE_TRACER", free_tracer);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment