KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Heap is a lot larger than used, how to find the cause? Re: Heap is a lot larger than used, how to find the cause?

  • Laura

    Administrator
    March 22, 2023 at 12:00 am

    Hi Nick,

    Understood on the QCE version not being an issue. So in my initial response to this I wasn’t able to replicate the issue with n:50000000, if you look at that you see I call position twice and the heap returns to normal.

    For n:2000000 I see the issue however so on the same page now:

     

    Regardless, did you try my fix I suggested in the latest response – as it works for both QCE and Q:

     

    See how if I delete position from the local namespace before reassigning it the heap returns to normal after GC.

    I think your theory about the first block allocation then second block use on second IPC call is correct. The reason I didn’t see this for the n=50000000 case was because the data was of a size that the memory allocated was large enough to hold both the IPC read and what was currently in memory without allocating another block. For the data you’re using or the n=2000000 case the memory allocated was nearer to the amount taken up by the object in memory.

    So my solution of deleting from the local namespace before calling again reduces the used memory in the process enough to be able to contain the second assignment and stop the invocation of the second block. Important to note that if you delete from the local namespace immediately before the second assignment this shouldn’t affect your code since the reassignment would overwrite the variable anyway.