On Friday, September 4, 2015 at 2:22:58 PM UTC, Arch Call wrote:
>
> Sorry, I meant allocation not leak.
>

Am I missing something, why is it important? The garbage collection (GC) 
will take care of the allocations, and if you are worried about, not the 
allocation, but the indirect time it takes (the eventual GC) I wander why?

This seems to be a test case.. you could have just done: 
sleep(sleep_time*num_iters) ..

I can only see that memory allocation in sleep or otherwise being a problem 
in some real-time applications, say a game. If it is important for this (or 
other function) then I'm sure if can be rewritten to get rid of the 
allocations.

OR it is just annoying you while debugging some bigger function.. does it 
need sleep()?

-- 
Palli.


> On Friday, September 4, 2015 at 9:56:48 AM UTC-4, Arch Call wrote:
>>
>> I am have difficulty in firguring out why WhyMemoryLeak() leaks memory, 
>> and NoMemoryLeak() does not!!
>> They are both identical except for the line in the for loop.
>>
>> It is driving me nuts!
>>
>> I am running Julia 3.11 and Windows 10.  This happens in Juno and in the 
>> REPL.
>>
>> Does anyone have any ideas?
>>
>> Thanks...Archie
>>
>>
>> #------------------------ sample Julia Program
>> function WhyMemoryLeak(num_iters::Int64, sleep_time::Float64)
>>   for i = 1:num_iters
>>     sleep(sleep_time)
>>   end
>>   return nothing
>> end
>>
>> function NoMemoryLeak(num_iters::Int64, sleep_time::Float64)
>>   for i = 1:num_iters
>>     sqrt(i) * sleep_time
>>   end
>>   return nothing
>> end
>>
>> #--------- simulate the actual sleep_ns process computing actual sleep 
>> times ----------
>> sleep_time = .003
>> println("-- results for NoMemoryLeak --")
>> @time NoMemoryLeak(10, sleep_time)   #-- warm up NoMemoryLeak
>> @time NoMemoryLeak(100, sleep_time) #-- run NoMemoryLeak with 100 iters
>> @time NoMemoryLeak(1000, sleep_time) #-- run NoMemoryLeak with 1000 iters
>>
>>
>> println("\n-- results for NoMemoryLeak --")
>> @time WhyMemoryLeak(10, sleep_time)  #-- warm up WhyMemoryLeak
>> @time WhyMemoryLeak(100, sleep_time)  #-- run WhyMemoryLead with 100 iters
>> @time WhyMemoryLeak(1000, sleep_time)  #-- run WhyMemoryLead with 100 
>> iters
>>
>> #---- results of run
>>
>>    - 
>>    
>>    -- results for NoMemoryLeak --
>>    
>>    - 
>>    
>>    elapsed time: 0.004308194 seconds (72968 bytes allocated)
>>    
>>    - 
>>    
>>    elapsed time: 4.521e-6 seconds (80 bytes allocated)
>>    
>>    - 
>>    
>>    elapsed time: 4.931e-6 seconds (80 bytes allocated)
>>    
>>    -- results for NoMemoryLeak --
>>    
>>    - 
>>    
>>    elapsed time: 0.048005713 seconds (70748 bytes allocated)
>>    
>>    - 
>>    
>>    elapsed time: 0.431385715 seconds (39280 bytes allocated)
>>    
>>    - 
>>    
>>    elapsed time: 4.346366676 seconds (392080 bytes allocated)
>>    
>>    
>>
>>

Reply via email to