| The cause of this appears to be two behaviors in the following section of code in lib/puppet/functions/new.rb:
def new_function_for_type(t, scope) |
@new_function_cache ||= Hash.new() {|hsh, key| hsh[key] = key.new_function.new(scope, loader) } |
@new_function_cache[t] |
end
|
https://github.com/puppetlabs/puppet/blob/6.18.0/lib/puppet/functions/new.rb This maintains a cache of constructor functions for each datatype: new String, new Integer, etc. The two issues are:
- The cache is a Hash instance with a lambda function that creates constructor functions as they are requested. This lambda closes over the Compiler scope value passed the first time new() is called, which keeps that scope in memory.
Aside from the memory leak, it seems wrong to be using the scope of the first Compiler that happens to call new() to provide data for subsequent compilations. |