It accumulates across your entire session. You can reset with `clear_malloc_data`.
The 48 bytes only include a _pointer_ to the Dict. You'd need to also include the space used by the Dict itself. One easy way to get an approximate number is @allocated ["H" => xHutil, "L" => 100 - xHutil] (It's approximate because returning values to the REPL also sometimes involves allocation. Putting things inside functions can improve the accuracy.) As I said, it's not actually the looping that's causing the allocation, it's the push! command. This page might be helpful: http://en.wikipedia.org/wiki/Dynamic_array The way julia "translates" for loops into while loops means that some events that happen at the end of the body might be mis-attributed to the for statement. --Tim On Friday, November 14, 2014 05:13:30 PM Test This wrote: > Thank you for the response Tim. > > sizeof(Person) is 48. Now, I know you said that it is not as > straightforward as looking just sizeof(Person). But when sizeof(Person) is > 48 and I have > 1728000 bytes allocated to Line 56, then is this more or less a certain > sign that something is wrong. Or, is 1728000 the total memory > that is ever used by the program in its entire run? > > * 1728000 p = Person(id, ["H" => xHutil, "L" => 100 - xHutil], > goods["N"], 0.0, false, 0) # LINE 56* > > Similarly, sizeof(Int) = 8. However, in line 66, I see the following. > > * 51457 for i = 1:params.numPeople * > > Given that numPeople=1000, should this be 8000 and not 51457? > > Thank you. > > On Friday, November 14, 2014 10:59:20 AM UTC-5, Tim Holy wrote: > > By "unexpected memory usage", it really means a line that shouldn't be > > allocating that nevertheless does. In your case, line 56 is explicitly > > allocating (it's creating a new Person object). You could check by using > > sizeof(Person) and seeing if the size is correct (but you'd have to > > include > > the size of the Dict, which because a Dict stores arrays is a bit > > recursive). > > Likewise, your push! command will grow the array, and hence allocate > > memory. > > That's being attributed to the first line of the for loop (the reasons are > > a > > little complex, and I'm late for a meeting). > > > > --Tim > > > > On Thursday, November 13, 2014 04:01:52 PM Test This wrote: > > > On performance tips page of the Julia documentation, it says that one > > > > way > > > > > to identify performance problems is to look for unexpected memory usage. > > > > > > As suggested, I ran the code with --track-allocation=user option. > > > > > > The following are some lines from my code (including the type > > > > definitions > > > > > at the beginning). For now, I have two questions: > > > > > > (1) How do I know what is appropriate/expected memory usage? That is, > > > > how > > > > > do I calculated expected appropriate usage? A related question is, is > > > > the > > > > > usage on line 56 appropriate. > > > > > > (2) What determines the memory usage for a for-loop? Is the usage on > > > > Line > > > > > 66 appropriate? > > > > > > Thank you. > > > > > > - ## > > > > > > ------------------------------------------------------------------- > > > > > > - ## Custom types and constants > > > - ## > > > > > > ------------------------------------------------------------------- > > > > > > - > > > - type Params > > > - minUtil::Int > > > - maxUtil::Int > > > - numPeople::Int > > > - w::Int # inversely related to the weight on reviews > > > - pReview::Float64 > > > - numReps::Int > > > - recEveryX::Int > > > - end > > > - > > > - > > > - type Good > > > - name::ASCIIString > > > - mu::Int > > > - sigma::Int > > > - end > > > - > > > - > > > - > > > - type Person > > > - id::Int > > > - priors::Dict{ASCIIString, Float64} > > > - choice::Good > > > - util::Float64 > > > - review::Bool #whether reviews or not > > > - stars::Int #if review=true then how many stars > > > - end > > > - > > > - > > > - > > > - ## > > > > =================================================================== > > > > > - ## Functions > > > - ## > > > > =================================================================== > > > > > - > > > - # Function to initialize a person > > > - function createPerson(params::Params, > > > - id::Int, > > > - xUtilDist::Dist.Uniform, > > > - goods::Dict{ASCIIString, Good}) > > > - # draw xH value > > > 0 xHutil::Float64 = rand(xUtilDist) > > > > > > * 1728000 p = Person(id, ["H" => xHutil, "L" => 100 - xHutil], > > > goods["N"], 0.0, false, 0) # LINE 56* > > > > > > - end > > > - > > > - > > > - # create population of persons with there initial xH and xL > > > - function createPopulation(params::Params, > > > > > > goods::Dict{ASCIIString, Good}) > > > > > > 288 popn::Array{Person, 1} = [] > > > > > > - #create a uniform distn with support [0, 100] > > > 0 unif = Dist.Uniform(params.minUtil, params.maxUtil) > > > - > > > > > > * 51456 for i = 1:params.numPeople # LINE 66* > > > > > > 0 p::Person = createPerson(params, i, unif, goods) > > > 0 push!(popn, p) > > > - end > > > - > > > 0 return popn > > > - end
