# OutOfMemoryError() instead of allocating too much resources in the job scheduler

**URL:** https://discourse.julialang.org/t/outofmemoryerror-instead-of-allocating-too-much-resources-in-the-job-scheduler/45575
**Category:** General Usage
**Created:** [August 26, 2020, 1:15pm UTC](https://discourse.julialang.org/t/outofmemoryerror-instead-of-allocating-too-much-resources-in-the-job-scheduler/45575 "2020-08-26T13:15:23Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)
#### Post date: [August 26, 2020, 2:06pm UTC](https://discourse.julialang.org/t/outofmemoryerror-instead-of-allocating-too-much-resources-in-the-job-scheduler/45575/4 "2020-08-26T14:06:16Z")

</div>

Wait, I found a mistake in the reference I’ve linked. You need to close the file in the referenced function. Otherwise you may get an error message like “too many files open” if you call that function very often. For convenience, here is the repaired version:

```julia
function get_mem_use()
    f::IOStream = open( "/proc/self/stat", "r" )
    s::AbstractString = read( f, String )
    vsize::Int = parse( Int64, split( s )[23] )
    mb::Int = Int( ceil( vsize / ( 1024 * 1024 ) ) )
    close(f)
    return mb::Int
end

```

I use this mainly in callbacks in JuMP.jl. Clearly, you cannot avoid all `OutOfMemoryError()` with this method if you put your “julia memlimit” too close to you physical limit. However, for me it works fine and I really have this errors very rarely now.

---

_[View the full topic](https://discourse.julialang.org/t/outofmemoryerror-instead-of-allocating-too-much-resources-in-the-job-scheduler/45575)._
