1

Possible Duplicate:
C# Compiler optimization - Unused methods

A JIT compiler runs after the program has started and compiles the code (usually bytecode or some kind of VM instructions) on the fly (or just-in-time, as it's called) into a form that's usually faster, typically the host CPU's native instruction set. A JIT has access to dynamic runtime information whereas a standard compiler doesn't and can make better optimizations like inlining functions that are used frequently.

This is in contrast to a traditional compiler that compiles all the code to machine language before the program is first run.but my question is Does the JIT compiler eliminate empty methods? Can someone give a succinct and easy to understand description?

Community
  • 1
  • 1
  • You can still load an executable as an assembly in other code, what would you expect to happen then? – user1908061 Feb 03 '13 at 19:53
  • what are u talking about? –  Feb 03 '13 at 19:55
  • @user1908061 Unreferenced private methods could theoretically be optimized out. Not sure if this was what Shahrooz had in mind, though, and I'm doubtful that JIT would actually do this optimization, but I haven't checked. On the other hand, reflection allows accessing private methods, so optimizing them out probably wouldn't be a good idea. – JLRishe Feb 03 '13 at 19:55
  • @JLRishe Accessing private methods using reflection is not a good idea either. ;) – user1908061 Feb 03 '13 at 19:59
  • @user1908061 I'd surely agree with that, but making them vanish without a trace in the interest of optimization is arguably worse. :) – JLRishe Feb 03 '13 at 20:11

3 Answers3

1

It is not, I just tested it by adding an unused function to my current project, and dotPeeking into the exe. It was still there.

It'sNotALie.
  • 22,289
  • 12
  • 68
  • 103
1

You can switch optimization off, even in release mode. So I think your question is: are private methods removed in optimized mode. And then the answer is no.

I think it's widely discussed here: C# Compiler optimization - Unused methods

(PS: that's a first hit in google when I just copy/paste your title)

Community
  • 1
  • 1
bas
  • 13,550
  • 20
  • 69
  • 146
0

This previous question might answer your question. It seems that it is not compiled however those unused methods will never be called. This doesn't seem to effect the memory footprint as JIT will bring those parts into memory as needed.

Community
  • 1
  • 1
DormeoES
  • 101
  • 8