9. Twice the @, Twice as Classy



I'm start to using @@class_variable and have a questin aboit it.
In this lesson we learn about OOP encapsulation principle, I suppose.
In Ruby (like in Java) we can use Threads for our programs.
So. I've created a class and threads that creating objects from my class.
I've putted some @@counter in it for counting created objects or what ever.
Did this @@counter counts all created objects or objects created only for this thread?
I know that in Java I can use 'volatile' variables and some synchronization. What about Ruby?


I cannot speak for Threads and concurrency in Ruby. As applied in this exercise, @@person_count will increment with each and every new instance of the class.


Ok, thnx. :3
It means only one thing. Need to test it. xD
Oh, and one more thing.
What about destroying instance of the class?
Do I need to clear the memory by myself? As in the C language.


Ruby looks after garbage collection for us when there are no longer any references to an object, or the object falls out of scope. From what I understand (though vaguely, sorry) we are not encouraged to do manual garbage collection. Manage the references, instead.

Needs more background research...


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.