[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Memory Leaks with foreign libraries
From: |
Matthew David Parker |
Subject: |
[Chicken-users] Memory Leaks with foreign libraries |
Date: |
Thu, 2 Feb 2006 17:58:45 -0500 (EST) |
Hello, I have a bad memory leak for my game I've incorperated with
Chicken.
My game is just an X windows network game that I compiled into a library
and I start the game in a chicken thread using:
(thread-start! (make-thread game_launch))
Then in my game loop, which is all in the compiled game library that was
written in C, I have an AI_loop() function that gets called once every
gameplay frame. At the bottom of this it calls "callback();"
Then in chicken I have defined:
(define-external (callback) void
(thread-yield!))
So this way I can play the game and enter commands into chicken at the
same time.
There is a memory leak, though, and it leaks even when the ship is just
sitting there on the screen with no calls to "malloc" or "free". I am
wondering if it has something to do with the callback, because, as it is
written:
"Non-local exits leaving the scope of the invocation of a callback from
Scheme into C will not remove the C call-frame from the stack (and will
result in a memory leak)."
Does that apply to my situation? I don't really understand it.
I also have my own TCP implementation written in C that that I use in
Chicken. That one has some memory leaks as well, though it doesn't have a
callback function. It does a lot of "malloc" and "free" but it works
without a leak if you use it with a C program. I don't know what the leak
there could be. What about passing strings between C and scheme? Do you
have to do something special to allocate new space for strings in chicken?
I have a lot of functions that I call from scheme into C, where C returns
a string, and they are just normal C functions that return some pointer in
memory to a string, then I access them through chicken with this:
(define AI.msg.body?
(foreign-safe-lambda c-string "FI_AImsg_body" int))
So I'd just call (AI.msg.body?) and it would return some string.
Are there any other obvious things I could check for that might cause a
memory leak?
Thank you,
Matt
- [Chicken-users] Memory Leaks with foreign libraries,
Matthew David Parker <=