Questions tagged [objectspace]

18 questions
11
votes
3 answers

ObjectSpace - what is it and how do people use it?

Ruby-doc has this description: The ObjectSpace module contains a number of routines that interact with the garbage collection facility and allow you to traverse all living objects with an iterator. ObjectSpace also provides support for …
6
votes
3 answers

ruby 2.0 undefined method ObjectSpace.trace_object_allocations

tried this on ruby 2.0.0 / 247 or head: require 'objspace' ObjectSpace.trace_object_allocations -> undefined method `trace_object_allocations' for ObjectSpace:Module Docs say it should work…
grosser
  • 14,707
  • 7
  • 57
  • 61
5
votes
1 answer

What's the meaning of each hash value in ObjectSpace.count_objects?

In ruby 1.9.3, I'm using ObjectSpace to inspect the memory issue. The ObjectSpace.count_objects returns a hash, which looks like: {:TOTAL=>1004232, :FREE=>258543, :T_OBJECT=>12519, :T_CLASS=>10318, :T_MODULE=>1330, :T_FLOAT=>2024,…
Bruce Lin
  • 2,700
  • 6
  • 28
  • 38
4
votes
1 answer

Explanation on Ruby ObjectSpace object allocation trace?

I'm trying to debug memory leak in a Rails App, and I'm trying to get a dump of existing objects, by using ObjectSpace#trace_object_allocations. In order for me to better understand the output, I think I should fully understand the meaning of an…
songyy
  • 4,323
  • 6
  • 41
  • 63
3
votes
2 answers

ObjectSpace.each_object(Foo).count

I'am trying to figure out ObjectSpace.each_object In console: class Foo; end Foo.new ObjectSpace.each_object(Foo).count => 1 GC.start ObjectSpace.each_object(Foo).count => 1 I've seen examples and I know that the second count should be…
Anton
  • 540
  • 3
  • 13
3
votes
1 answer

Can eigenclasses be enumerated?

Calling ObjectSpace.each_object(Class) does not seem to return any eigenclasses. For example, when investigating Ruby metaclasses: why three when defined singleton methods?, I found that while ObjectSpace.count_objects[:T_CLASS] was getting…
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
3
votes
0 answers

How to implement com.objectspace.jgl package?

I downloaded a code from internet which uses the following code import com.objectspace.jgl.*; import com.objectspace.jgl.Array; import com.objectspace.jgl.algorithms.Shuffling; import com.objectspace.jgl.algorithms.Sorting; import…
shujin
  • 181
  • 12
2
votes
1 answer

Is ObjectSpace still disabled in jruby?

Is ObjectSpace still disabled in jruby 9.1.5.0 (2.3.1)? If it's not just my installation (Arch Linux, up-to-date) having a bug, I get the suspicion that ObjectSpace has changed in recent jruby: Trying to reproduce the behaviour described in jruby's…
Kalsan
  • 822
  • 1
  • 8
  • 19
2
votes
0 answers

Is it a good idea to use ObjectSpace to find parent ActiveRecord in a validation chain?

Considering following models: class Father < ActiveRecord::Base has_many :children, as: :parent, dependent: :destroy accepts_nested_attributes_for :child end class Child < ActiveRecord::Base belongs_to :parent, polymorphic: true validates…
Yan Foto
  • 10,850
  • 6
  • 57
  • 88
2
votes
2 answers

Why does `ObjectSpace.each_object(String)` include just about any string?

After comments by Mike H-R and Stefan to a question of mine, I noticed that ObjectSpace.each_object(String) includes just about any string I can think of: strings = ObjectSpace.each_object(String) strings.include?("some random string") # =>…
sawa
  • 165,429
  • 45
  • 277
  • 381
2
votes
1 answer

Rails application not freeing memory?

In my rails application total object are increasing with every request. Objects are not freeing after GC runs. I am using Rails 3.2.3 and ruby 1.9.3. Can someone point me in right direction ? Where to start? What are the available tools ? Tools…
krunal shah
  • 16,089
  • 25
  • 97
  • 143
1
vote
1 answer

Is it possible with Ruby reflection to retrieve all the objects containing a reference to some "var.object_id"?

Suppose in Ruby I have a = "value"; arr1 = [a, b, c]; and arr2 = [a, d, e]; Is there some reflective programming technique allowing me to say: What are all the objects which have a reference to a.object_id? and getting as an answer something…
Redoman
  • 3,059
  • 3
  • 34
  • 62
1
vote
0 answers

Why are there missing file names and lines in Ruby 2.1's ObjectSpace.dump_all heap output?

I recently profiled a bunch of Ruby 2.1.2 code using the new ObjectSpace.dump_all method. I got back some useful data (using the script that @tmm1 suggests in that link): 931…
subelsky
  • 405
  • 6
  • 12
1
vote
1 answer

Java FlyServer Fly Object space

I have developed a Java application using The ‘Fly’ Object Space. After writing an object from the FlyServer to the FlySpace, there is a line of code as follows: long res = space.write(dc, 10000); Can someone explain to me what this line of code…
user2381256
  • 101
  • 2
  • 2
  • 5
0
votes
1 answer

How to call ObjectSpace.each_object with C API without rb_string_eval?

I'm currently trying to get all the instances of a class and I wanted to use ObjectSpace.each_object to achieve that. Here is my actual code in C : ruby_init(); int ruby_state = 0; rb_string_eval_protect("def my_func ; ObjectSpace.each_object(Klass)…
Sisyphe
  • 146
  • 1
  • 13
1
2