Tag Info

Hot answers tagged

97

You really can't make blanket statements about appropriate way to use all GC implementations. They vary wildly. So I'll speak to the .NET one which you originally referred to. You must know the behaviour of the GC pretty intimately to do this with any logic or reason. The only advice on collection I can give is: Never do it. If you truly know the ...


56

Sadly, nobody there elaborates on what are such cases. I'll give some examples. All in all it is rare that forcing a GC is a good idea but it can be totally worth it. This answer is from my experience with .NET and GC literature. It should generalize well to other platforms (at least those that have a significant GC). Benchmarks of various kinds. You ...


26

As a general principle, a garbage collector will collect when it runs into "memory pressure", and it's considered a good idea to not have it collect at other times because you could cause performance problems or even noticeable pauses in your program's execution. And in fact, the first point is dependent on the second: for a generational garbage collector, ...


19

You haven't said whether the filters take any parameters. For example, filter_A might be a category filter, so that it's not just a question of "do I need to apply filter_A", it could be "I need to apply filter_A and return all records in with the category field = fooCategory". The simplest way to implement exactly what you've described (but make sure to ...


14

Your optimization wish (of transforming a sequence of if into the equivalent of a switch) makes sense only (as Jörg W Mittag wisely commented) for idempotent conditions (which are undecidable to detect in general). But we could restrict these conditions to be a disjunction of equality tests like x == k where x is always the same (SSA-form) simple scalar ...


10

One thing no one has mentioned is that, while the Windows GC is amazingly good, the GC on Xbox is garbage (pun intended). So when coding an XNA game intended to run on XBox, it's absolutely crucial to time garbage collection to opportune moments, or you'll have horrible intermittent FPS hiccups. Additionally, on XBox it's common to use structs way, way ...


4

Language consistency The discoverability of the actual constant to use in a given language is not a big deal either. I've never used this constant in Java, but a simple Google search for "java int max value" leads to Integer.MAX_VALUE just by glimpsing on the Google results, without even opening any additional page. How fast is that? More importantly, the ...


4

Garbage collection is first and foremost a memory management tool. As such, garbage collectors will collect when there is memory pressure. Modern garbage collectors are very good, and getting better, so it's unlikely that you can improve on them by collecting manually. Even if you can improve things today, it may well be that a future improvement to your ...


3

I can think of two possible solutions here, but they both require a fair amount of development (but I really can't see a solution where this is not the case). I would also recommend not developing any specific kind of check step until it is actually needed. It's very easy to have requirements for 42 different kinds of automated steps that end up having only ...


3

For what its' worth, the article you linked was discussing people who write promise libraries, not people who use them. Your use case seems a bit larger than typical, but as far as I can tell from your description, it's a relatively good fit for promises. Promises are designed to simplify sequencing and composition of asynchronous code. That's certainly ...


3

In this case, it is important to separate the logic of filtering, and the control flow of how the filters run. The filter logic should be separated out into individual functions, that can run independent of each other. ApplyFilterA(); ApplyFilterB(); ApplyFilterC(); In the sample code posted, there's 3 booleans filter_A, filter_B, and filter_C. However, ...


3

There is no commonly accepted decimal notation for Unicode codepoints. Unicode codepoints are almost universally represented in hexadecimal. The sole exception I'm aware of is the use of Numeric Character References (NCRs) in languages derived from SGML (e.g., HTML and XML), which can take one of two forms: &#nnn; in decimal or &#xnnn; in ...


2

I assume, that you want the simplest, clearest algorithm. In this case, knowing that filter c is always applied, I would live it out of the if logic and apply it at the end regardless. As it looks in your flowchart, each filter before the c, is optional, because each of them can either be applied, or not. In this case, I would live ifs separate from each ...


2

There are several cases where you might want to call gc() yourself. [Some people say that this is not good because it may promote objects to older generation space which I agree is not a good thing. However, it is NOT always true that there will always be objects which can be promoted. It is certainly possible that after this gc() call, very few objects ...


2

The best practise is to not force a garbage collection in most cases. (Every system I have worked on that had forced garbage collections, had underlining problems that if solved would have removed the need to forced the garbage collection, and speeded the system up greatly.) There are a few cases when you know more about memory usage then the garbage ...


2

A real-world example: I had a web application that made use of a very large set of data that rarely changed and which needed to be accessed very quickly (quick enough for per-keystroke response via AJAX). The obvious enough thing to do here is to load the relevant graph into memory, and access it from there rather than the database, updating the graph when ...


1

I have a usage for garbage disposal which is somewhat unorthodox. There is this misguided practice which is unfortunately very prevalent in the C# world, of implementing object disposal using the ugly, clunky, inelegant, and error prone idiom known as IDisposable-disposing. MSDN describes it in length, and lots of people swear by it, follow it religiously, ...


1

I'm going to assume filterA, filterB, and filterC actually modify the list of products. Otherwise, if they are just if-checks, then filterA and filterB can be ignored since all paths lead ultimately to filterC. Your description of the requirement seems to imply that each filter will reduce product list. So assuming the filters actually reduce the list of ...



Only top voted, non community-wiki answers of a minimum length are eligible