mkajdas.mkprod wrote:
>> When you say 'create and print', what steps are involved?
>> Are you taking a screenshot with an external tool, or using
>> fltk's printing support?
>
> I do all of the printing myself thru USB.
> I create an image in memory using FLTK widgets and then just 'write' the
> image to the printer. No high level interface is involved.
> Therefore, I am certain that FLTK is causing memory loss.
What FLTK functions are you using to create the image in memory?
I can only think of 'fl_read_image()'
If possible, post a small working program if you can so we can
replicate.
It would seem doubtful it's Fl_Double_Window and a few widgets alone
would be leaking significant memory.. it's more likely the screenshot
code (either in fltk or your app) is not free'ing something.
One thing to watch out for when looking at the OS's free memory..
just because free(3) is called doesn't mean it gets reclaimed by the OS.
Basically this age old problem:
http://groups.google.com/group/comp.lang.c/browse_thread/thread/70a55e2a058f7853/3eabc8bfcdf1a307?hl=en&lnk=st&q=free+sbrk#3eabc8bfcdf1a307
..specifically the first and last messages in that thread.
The above is the same reason the following app shows /proc/meminfo
is not reclaiming the large allocations of memory even after they've
been free(3)ed:
---- snip
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <memory.h>
int main()
{
// SIMULATE ALLOCATING A LOT OF SCANLINES
const int width = 1024;
const int height = 2048;
void *scans[height];
fprintf(stderr, "BEFORE MALLOC: ");
system("grep MemFree: /proc/meminfo");
// allocate large blocks (scanlines)
{
size_t bytes = width * 4 * sizeof(long);
for ( int t=0; t<height; t++ )
{
scans[t] = malloc(bytes);
memset(scans[t], 0, bytes);
}
}
// allocate some small blocks
void *small1 = malloc(12); memset(small1, 0, 12);
void *small2 = malloc(37); memset(small2, 0, 37);
fprintf(stderr, " AFTER MALLOC: ");
system("grep MemFree: /proc/meminfo");
// free large blocks, leave small still allocated
{
for ( int t=0; t<height; t++ )
free(scans[t]);
}
sleep(1); // allow time for os to move stuff around
fprintf(stderr, " AFTER FREE: ");
system("grep MemFree: /proc/meminfo");
return(0);
}
---- snip
..when I run this on my linux machine, I get:
BEFORE MALLOC: MemFree: 34776 kB
AFTER MALLOC: MemFree: 3404 kB
AFTER FREE: MemFree: 3404 kB
..note that 'AFTER FREE' reports /nothing/ has been reclaimed by the OS,
even though megabytes have been free(3)ed. Every time I run it I get
different results. Sometimes a few kB have been freed, sometimes not.
This isn't showing a memory leak, but just business as usual with
how the heap and memory holes are managed.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk