[gambit-list] Help With Memory

Joel J. Adamson <adamsonj@email.unc.edu> adamsonj at email.unc.edu
Wed Sep 24 13:31:44 EDT 2008


>>>>> "chj" == Christian Jaeger <christian at pflanze.mine.nu> writes:

    chj> I don't have the time to dig into your code. Just to make sure:
    chj> - be sure to compile the program;

I have the same problem (at least the same result as far as the crash is
concerned) with compiled or interpreted versions.


    chj> (For debugging, also make sure you know how to use
    chj> |generate-proper-tail-calls|.)

I have used (generate-proper-tail-calls #f): is there more to it than
that?  Where can I read about it?

    chj> - find out what the reason of the out of memory situation could
    chj> be: is (a) your problem maybe just asking for more memory than
    chj> you've got?, or (a2) your problem doesn't necessarily ask for
    chj> more memory than you've got in principle, but the way you're
    chj> evaluating it (e.g. calculate to eagerly) requires too much
    chj> memory at once, or (b) you've got an error in the program which
    chj> leads to an infinite loop allocating memory, or (c) your
    chj> program is holding on to memory that it doesn't need anymore?

I would find (c) to be the most plausible choice; can I rule out the
other two by tweaking my parameters?  If I run fewer iterations, I don't
have the problem and the program completes successfully --- that means
if I create fewer structs, 1000 versus 2000 --- I don't have the problem.

    chj> For (c) check your assumptions about the lifetime of memory:
    chj> particularly, be aware that structs (as defined using
    chj> define-structure or define-type), or in fact any data structure
    chj> like cons cells and vectors, will hold on to every location in
    chj> them

Okay, so am I screwed here?  Just kidding: if I bind them lexically, I
would need to get the data out of them before exiting that closure
(tail-calling my "data-collection" function) --- I can do that.

    chj> (this is unlike lexical bindings, which, as I've told above,
    chj> will be analyzed by the compiler and only live as long as the
    chj> program will possibly refer to them). 

Just to make sure I'm understanding: if I do everything with a
particular data structure within a lexical closure, then I can use
whichever sort of data-structure I want (struct, list, vector, etc).

As an example,

(define-structure female
  mating-status
  mated
  not-mated
  strategy
  age
  times-mated)


(define (do-struct i)
	(let ((struct (make-female
	     #f
	    '()
	    '()
	     (random-strategy) 1 0)))
	     (do ((j 0 (+ 1 j)))
	         ((= j 5) (print (female-age struct) "\n"))
		 (female-age-set struct (+ j (female-age female))))))

This `female' structure is going to get gc'ed when do-struct exits?

    chj> Note that when heeding these precautions I could never get
    chj> Gambit to leak memory in compiled programs.

Good to know.

Thanks,
Joel

-- 
Joel J. Adamson
University of North Carolina at Chapel Hill
CB #3280, Coker Hall
Chapel Hill, NC 27599-3280

Before you reply to this email, please read
http://www.unc.edu/~adamsonj/email-howto.html



More information about the Gambit-list mailing list