Re: Why are my maps chewing on my RAM? or, Adventures in memory (de)allocation

new topic     » goto parent     » topic index » view thread      » older message » newer message
ghaberek said...

I'm working on the new code base for the website, which also acts as a proving ground for Euphoria MVC.

This problem is pretty obvious when you think about it, but it caught me off guard and my hand-spun web server started chewing pretty hard on my RAM.

This is a simplified example of the code I'm working with. Can you spot the problem? Hint: models are maps, which use eumem.

namespace messages 
constant MESSAGE = model:define( ... ) 
-- return a message object matching the provided query string 
public function fetch_one( sequence query ) 
    object message = model:fetch_one( MESSAGE, query ) 
    if map( message ) then 
        integer message_id = map:get( message, "id" ) 
        -- retrieve the associated replies 
        sequence replies = model:fetch_all( MESSAGE, 
            "WHERE parent_id = %d AND is_deleted = 0", 
        map:put( message, "replies", replies ) 
    end if 
    return message 
end function 

Do you see it yet?

The pseudo memory library automatically tags the objects it allocates with delete_routine() to mark the object's slot as "free" when it goes out of scope.

So when you allocate a bunch of maps, put them into a sequence, and then store that sequence in another map, what happens when the map goes out of scope?

Nothing! Cleanup routines are chained, but they're not recursive, so the maps just hang around even though the sequence they're in went out with the main map...


Please excuse my ignorance but why can't maps be just normal sequences that encapsulate hash tables? Wouldn't that solve memory allocation issues?


new topic     » goto parent     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu