On Wednesday, September 10, 2003, 3:09:20 AM, David wrote:

>> I don't think so - I think all the modules are loaded when Apache is
>> started, and each child process will have everything in the parent
>> process.  In fact, when I put a LoadModule directive inside a
>> VirtualHost section, apachectl configtest reported an error.

> It didn't have anything to do with IfModules or even Apache. I had a 
> static constructor method as follows:

> def self.run
>         @request = CGI.new
>         self.new(@request, @request.session(Session_parameters))
> end

> Can you spot the instance variable reference? That caused a massive 
> memory leak of a couple of hundred kb on each run.

> I wonder why Ruby didn't alert me to the presence of a instance 
> reference in a static context? Java does that.


You've tripped on a funny feature of Ruby which some people have
grasped and I ... well, haven't.  Sorry I can't think of a reference
right now.

But basically,

  class Example
    @x = "class instance variable"
    @@x = "class variable"

    def initialize
      @x = "instance variable"
    end

    def run
      puts @x
      puts @@x
    end

    def self.run
      puts @x
      puts @@x
    end
  end

  Example.run
  Example.new.run


Run this code yourself to see the (predictable) output.

I just created http://www.rubygarden.org/ruby?ClassInstanceVaribles.
If anyone knows of links to other information about them, that would
be a good place to gather them.

Gavin