Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BUG] Memory accumulation when using load_image in a loop

Open
#365 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
rust

Research direction

Start by running the supplied loop in src/main.rs:6 and inspect the load_image wrapper at src/image/mod.rs:317, along with the reported native af_load_image path. Trace whether repeated image loading retains device memory and identify the relevant cleanup or ownership behavior. Done means the reproduction no longer accumulates memory until an out-of-memory error, with a regression test for repeated loading.

Written by the indexing model from the issue text.

Description

Bug

The following program crashed. But why?

use arrayfire::*;

fn main() {
    let mut y =constant!(0 as u8;1);
    for i in 0..1000 {
        let x = load_image::<u8>("2dzs/robot_2dz.png".to_string(), true);
        let z = or(&x, &y, true);
        y = z.copy();
        println!("i={}", i);
    }
    println!("max(y)={:#?}", max_all(&y));
}

i=0
i=1
i=2
i=3
i=4
i=5
i=6
i=7
i=8
i=9
i=10
i=11
i=12
i=13
i=14
i=15
i=16
i=17
i=18
i=19
i=20
i=21
i=22
i=23
i=24
i=25
i=26
i=27
i=28
i=29
i=30
i=31
i=32
i=33
i=34
i=35
i=36
i=37
i=38
i=39
i=40
i=41
i=42
i=43
i=44
i=45
i=46
i=47
i=48
i=49
i=50
i=51
thread 'main' panicked at 'Error message: System or Device ran out of memory
Last error: In function af_load_image
In file src/api/c/imageio.cpp:393


 0# 0x00007F4FC1A299AF in /opt/arrayfire/lib/libafcuda.so.3
 1# 0x0000560F6F590AFF in target/debug/crash
 2# 0x0000560F6F590099 in target/debug/crash
 3# 0x0000560F6F5903AB in target/debug/crash
 4# 0x0000560F6F59031E in target/debug/crash
 5# 0x0000560F6F58FC41 in target/debug/crash
 6# 0x0000560F6F5A707F in target/debug/crash
 7# 0x0000560F6F58FC10 in target/debug/crash
 8# 0x0000560F6F5902EC in target/debug/crash
 9# 0x00007F4FFB823510 in /lib/x86_64-linux-gnu/libc.so.6
10# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
11# 0x0000560F6F58FB15 in target/debug/crash
', /home/joe/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/arrayfire-3.8.0/src/core/error.rs:37:14
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c07a8b4e09f356c7468b69c50cac7fc5b5000b8a/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/c07a8b4e09f356c7468b69c50cac7fc5b5000b8a/library/core/src/panicking.rs:142:14
   2: arrayfire::core::error::handle_error_general
             at /home/joe/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/arrayfire-3.8.0/src/core/error.rs:37:14
   3: arrayfire::core::error::Callback::call
             at /home/joe/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/arrayfire-3.8.0/src/core/error.rs:29:9
   4: arrayfire::core::error::HANDLE_ERROR
             at /home/joe/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/arrayfire-3.8.0/src/core/error.rs:95:5
   5: arrayfire::image::load_image
             at /home/joe/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/arrayfire-3.8.0/src/image/mod.rs:317:9
   6: crash::main
             at ./src/main.rs:6:17
   7: core::ops::function::FnOnce::call_once
             at /rustc/c07a8b4e09f356c7468b69c50cac7fc5b5000b8a/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Dominant language
Rust
Stars
827
Forks
59
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from arrayfire/arrayfire-rust

All issues in arrayfire/arrayfire-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.