ftp:close and garbage collection

knotwell@REDACTED knotwell@REDACTED
Sat May 8 01:32:04 CEST 1999


Hello all--

A question. . .I wrote a small ftphammer program.  When testing the
program, I noticed that it ran reasonably well at first but after a
short time the performance degraded to unacceptably.  Anyhow, 
using the process monitor, I noticed that ftp connections appeared to 
stay around after leaving the following function:

getData(Host,InFile,OutFile) ->
    FP = element(2,ftp:open(Host)),
    ftp:user(FP,"anonymous","knotwell@REDACTED"),
    case catch ftp:recv(FP,InFile,OutFile) of
	 ok    -> ok;
	 Other -> error
    end. 


It turned out I needed to do the following (in order to get everything 
to cleanup okay):
        
getData(Host,InFile,OutFile) ->
    FP = element(2,ftp:open(Host)),
    ftp:user(FP,"anonymous","knotwell@REDACTED"),
    case catch ftp:recv(FP,InFile,OutFile) of
        ok    ->
                ftp:close(FP),
                ok;
        Other -> error
    end.

Assuming that I'm correct in thinking that ftp connections are not
finalized automatically, is this:

1)  related to Erlang's inability to garbage collect atoms 
2)  enforcing good practice--making the programmer reclaim allocated
    resources
3)  a bug

A small aside:  it isn't really clear to me why there should be
separate open and user functions.  I suppose if your first
username/password didn't work and you wanted to try again without
forcing the server to spawn another ftpd.

Thanks.

--Brad










More information about the erlang-questions mailing list