Skip to content

Problem With Repeated Use Of Load/Save/Close Commands (PR#13841)

2 messages · Duncan Murdoch

#
On 17/07/2009 7:57 PM, Marilyn & Rich Short wrote:
This looks like a bug to me, and so I've posted it to the bugs list, but 
your script doesn't make sense for normal use.  Before the loop you 
create a file named according to conX containing the junk variable, and 
then within the loop you load that file, *then delete it*, using 
unlink().  However, if you examine the value of unlink(), you'll see 
that it fails every time.

Moreover, the use of connections is unnecessary:  load() can work with a 
filename.  So you can skip the file() and close() calls.

If I simplify your script by removing the unnecessary stuff, then it 
works.  That is, this works:

     junk       = 1
     PathA    = tempdir()
     conX     = paste(PathA,"junk",sep="\\")
     save(junk, file=conX)
     for(i in 1:4000){
         load(file=conX)
         rm(junk)
         cat(" i = ",i,sep=" ")
         gc()
         zzz = showConnections(all=FALSE)
         cat(" zzz = ",zzz,"\n",sep=" ")
     }

So a suggestion for a workaround is simply to follow the pattern above, 
rather than that of your demonstration code.

I'll spend a bit more time and see if I can find what is causing the 
open file leak.

Duncan Murdoch
#
On 18/07/2009 8:15 AM, murdoch at stats.uwo.ca wrote:
Now fixed in R-devel, R-patched coming soon.

Duncan Murdoch