• naonintendois@programming.dev
    link
    fedilink
    arrow-up
    8
    ·
    20 days ago

    You don’t need unsafe. Just keep pushing to a vec and never remove anything. Memory leaks are more than lost memory allocations. You can even have them with rc/arc cycles

    • thingsiplay@beehaw.org
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      20 days ago

      Yeah. Lot of people also use Ai generated code… so…

      I have tested if clippy would warn me with a simple example (generates 6.7gb memory usage, be careful not to crash your computer if you add another 0…), while I watch with a system monitor (in KDE):

      use std::thread;
      use std::time;
      
      fn main() {
          let mut vec = Vec::new(); // Create an empty Vector.
      
          for number in 0..900000000 {
              let bign: i64 = number * number;
              vec.push(bign);
          }
      
          thread::sleep(time::Duration::from_secs(10));
      }
      

      I used the pedantic option of clippy and the only thing it complained was about the notation of the number…:

      $ cargo clippy -- -W clippy::pedantic
      warning: long literal lacking separators
      --> src/main.rs:7:22
      |
      7 |     for number in 0..900000000 {
      |                      ^^^^^^^^^ help: consider: `900_000_000`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal
      = note: `-W clippy::unreadable-literal` implied by `-W clippy::pedantic`
      = help: to override `-W clippy::pedantic` add `#[allow(clippy::unreadable_literal)]`
      
      warning: `notright` (bin "notright") generated 1 warning
      Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
      
    • flashgnash@lemm.ee
      link
      fedilink
      arrow-up
      1
      ·
      18 days ago

      Surely that’s not a memory leak, that’s just the program using a lot of memory intentionally