Questions tagged [garbage]

Garbage, refers to objects, data, or other regions of the memory of a computer system (or other system resources), which will not be used in any future computation by the system, or by a program running on it.

From a programming point-of-view, garbage is data that has been placed in random access memory space obtained from the operating system that is no longer needed. Freeing the space for reuse is called "garbage collecting".

448 questions
339
votes
22 answers

Is uninitialized local variable the fastest random number generator?

I know the uninitialized local variable is undefined behaviour(UB), and also the value may have trap representations which may affect further operation, but sometimes I want to use the random number only for visual representation and will not…
ggrr
  • 7,737
  • 5
  • 31
  • 53
25
votes
2 answers

C# Does Lambda => generate garbage?

Does using a lambda expression generate garbage for the GC opposed to the normal foreach loop? // Lambda version Foos.ForEach(f=>f.Update(gameTime)); // Normal approach: foreach (Foo f in Foos) { f.Update(gameTime); } The CLR profiler shows that…
Napoleon
  • 1,072
  • 5
  • 17
  • 31
16
votes
4 answers

If a function returns no value, with a valid return type, is it okay to for the compiler to return garbage?

If a function has a return type other than void, and the function does not return anything, then I guess the compiler returns a garbage value (possibly seen as an uninitialized value). It happens at compile time, so why shouldn't it show an…
howtechstuffworks
  • 1,824
  • 4
  • 29
  • 46
13
votes
3 answers

Why does this test take longer without garbage collection overhead?

I ran into this scenario in the process of developing a lightweight library for asynchronous messaging. Trying to get an idea of the cost of creating lots of medium sized objects with short lifetimes, I wrote the following test: import…
735Tesla
  • 3,162
  • 4
  • 34
  • 57
12
votes
3 answers

What is the difference between garbage and dangling references?

What is the difference between garbage and dangling references?
user425243
12
votes
2 answers

Does Kotlin have a garbage collector? If so, on which algorithm is it based?

I'm doing a school project on Kotlin and need to know how it deals with garbage. Is it similar to Java in its garbage collector?
Dina Kleper
  • 1,949
  • 4
  • 17
  • 23
12
votes
1 answer

freachable queue and finalization queue

What is difference between freachable queue and finalization queue? One Solution:Transition from Finalization Queue to FReachable Queue .net Garbage Collection
8
votes
2 answers

clang-analyze: how to avoid "garbage value" warning?

When checking #include #include int main(void) { char c[20]; size_t l; l = fread(c, sizeof c, 1, stdin); if (l != 1) return 1; return c[0] == 42; } with clang, I get $ clang --analyze -Xclang…
ensc
  • 6,704
  • 14
  • 22
8
votes
1 answer

Kotlin: How can I avoid autoboxing (garbage) in delegated properties?

In my software, I have some various values which use property delegation. This is a simple similar example showing what I do: class ExampleDelegate(val value: T) { operator fun getValue(thisRef: Any?, property: KProperty<*>) = value } val…
Jire
  • 9,680
  • 14
  • 52
  • 87
7
votes
3 answers

Do two objects of a class refer to the same memory location?

I am starting to learn some Java and I have been reading a lot about how memory is allocated by the JVM and consequently how this memory is freed using the garbage collector. One thing that I have been unable to find out is if I create two new…
Anon87489384
  • 73
  • 1
  • 5
7
votes
5 answers

C# garbage collector seems to be closing my StreamWriter too early

I have a logger class thats a singleton. In it's destructor I call Close() which prints the footer for the log and then closes the StreamWriter. public void Close() { WriteLogFileFooter(); _logFile.Flush(); …
ForeverNoobie
  • 531
  • 5
  • 17
7
votes
6 answers

What will be the value of uninitialized variable?

Possible Duplicate: Is uninitialized data behavior well specified? I tried the following code #include void main() { int i; \ printf('%d',i); } The result gave garbage value in VC++, while same in tc was zero. What will be the correct…
Rajeev Kumar
  • 435
  • 2
  • 7
  • 20
6
votes
3 answers

Viewing garbage collection history in c# (VS2015)

A unforeseen and unanticipated amount of garbage collection activity is shown in the 'Process Memory' graph when I run my application which makes me want to know where in the program is the garbage generated as I don't feel that I have any memory…
hecate
  • 620
  • 1
  • 8
  • 33
6
votes
2 answers

Does garbage collection run immediately after GC.Collect()?

The question is just for research purposes. I've read many books about C# and this question always comes to my mind. What I understood that C# is managed code and all garbage collection occurs when CLR decides when to run garbage collection. Let's…
StepUp
  • 36,391
  • 15
  • 88
  • 148
6
votes
2 answers

.Net Framework 4.0 - Opcodes.Box present in Dictionary with int key

I'm trying to investigate whether dictionaries with enum keys still generate garbage in newer versions of .Net (say >= 4) See Shawn Hargreaves blog post here for details on why I'm even fretting about…
1
2 3
29 30