almost infinite loop

This is a discussion on almost infinite loop within the C++ Programming forums, part of the General Programming Boards category; Hi, If I do something like this, int var; byte [] b = null; while(1){ read var; b = new ...

  1. #1

    Question almost infinite loop


    If I do something like this,

    int var;
    byte [] b = null;

    read var;
    b = new byte[var]
    //process b


    will the program ever run out of memory. Will it create a new location everytime, the new stmt is executed. Will the old location be out of scope and dumped or stays hanging there without being used as long as the program doesn't exit

    The code is from java, but I want the concept clear.I did not show the full code, it assumes that while exits when program is shut down using ctrl-c or likewise.

    Thanks ,
    Future member.

  2. #2
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    this program will cause infinte loop , which will occure new location every time . and these ll not be cleared from memory as your program ll not close....................
    hope I helped you .......moemen ahmed

  3. #3
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    That code is totally memory leaky.
    MSVC++ 6.0

  4. #4
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Java does garbage collection. That's why that works in Java.
    C and C++ do not. This concept creates a memory leak, where the memory is allocated but there is no way to access it anymore.
    In a language with garbage collection, the garbage collector runs and is able to free up any memory that no longer has a way to be accessed. The new C# language does this as well, but good old C/C++ we get to do it ourselves.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2009, 11:24 PM
  2. Cosine fucntion and infinite loop.
    By youareafever in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 03:45 AM
  3. Infinite Loop with GetAsyncKeyState
    By guitarist809 in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2008, 12:09 PM
  4. Switch statement = infinite loop
    By Lucid003 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2005, 12:46 AM
  5. stays in loop, but it's not an infinite loop (C++)
    By Berticus in forum C++ Programming
    Replies: 8
    Last Post: 07-19-2005, 11:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21