Hi,

I detect memory problem in drawing by PSmoveto(), PSlineto.
In my example, the NSTimer is invoking draw of several lines to window content view.
The consumed memory of application is growed after each drawing.
Can somebody help me with this problem ? Do I something wrong ?

Thank you
Jan Trembulak.

Here is example
#import <AppKit/AppKit.h>

#define MAX_X   500
#define MAX_Y   300

@interface AppController : NSObject
{
    NSTimer *runTimer;
    id myWindow;
    
    int p1x,p1y, p2x,p2y;
    int s1x,s1y, s2x,s2y;
}

- (void) runTimer: (NSTimer *) aTmr;
@end

//----------------------------------------------
int main(int argc, const char *argv[])
{
        id pool = [NSAutoreleasePool new];
        id app;

#ifndef NX_CURRENT_COMPILER_RELEASE
        initialize_gnustep_backend();
#endif
//    GSDebugAllocationActive(YES);

        app = [NSApplication sharedApplication];
        [app setDelegate: [AppController new]];
        [app run];

        [pool release];
        return 0;
}
//----------------------------------------------

@implementation AppController

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{

    runTimer = [[NSTimer scheduledTimerWithTimeInterval:0.1
                                        target: self
                                      selector: @selector (runTimer:)
                                      userInfo: nil repeats:YES] retain];
    myWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect(0.,0.,MAX_X,MAX_Y)
                styleMask: NSTitledWindowMask
                  backing: NSBackingStoreBuffered
                     defer: YES];
    p1x= rand() % MAX_X;        p2x=rand() % MAX_X;
    p1y= rand() % MAX_Y;        p2y=rand() % MAX_Y;
    s1x = s1y = s2x = s2y = 1; 

    [myWindow makeKeyAndOrderFront: nil];
}


- (void) runTimer: (NSTimer *) aTmr
{
    static int counter = 0;
    int i;
    [[myWindow contentView] lockFocus];
    if (counter <50) [[NSColor redColor] set];
    else if (counter <100) [[NSColor blueColor] set];
    else { [[NSColor greenColor] set];  counter=0;}
    
    PSnewpath();        
    for (i = 0; i < 20; i++)
    {
        p1x += s1x;             p1y += s1y;
        p2x += s2x;             p2y += s2y;
    
        PSmoveto(p1x,p1y);
        PSlineto(p2x,p2y);
        PSmoveto(p1x,p1y);
        PSlineto(p2x,p2y);
        PSmoveto(p1x,p1y);
        PSlineto(p2x,p2y);
        PSmoveto(p1x,p1y);
        PSlineto(p2x,p2y);
        PSmoveto(p1x,p1y);
        PSlineto(p2x,p2y);
        PSmoveto(p1x,p1y);
        PSlineto(p2x,p2y);
        PSmoveto(p1x,p1y);
        PSlineto(p2x,p2y);
        PSmoveto(p1x,p1y);
        PSlineto(p2x,p2y);

        if (p1x>MAX_X) s1x= -(rand()%5);
        else if(p1x<0) s1x=rand()%5;
    
        if(p1y>MAX_Y) s1y=-(rand()%5);
        else if(p1y<0) s1y=rand()%5;

        if (p2x>MAX_X) s2x=-(rand()%5);
        else if(p2x<0) s2x=(rand()%5);
    
        if(p2y>MAX_Y) s2y=-(rand()%5);
        else if(p2y<0) s2y=(rand()%5);
    }
    PSstroke();
    PSinitclip();
    [[myWindow contentView] unlockFocus];
    [myWindow flushWindow]; 
    counter++;
}
@end:
 






Reply via email to