• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static methods

 
siva prakash
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

when we declare methods as static. does static methods occupy more memory than normal methods.



With Regards,
Siva
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when we declare methods as static

to call a static method you dont need to instantiate an object, just use ClassName dot MethodName

MyClass.myStaticMethod()
 
Ryan McGuire
Ranch Hand
Posts: 1078
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by siva prakash:
does static methods occupy more memory than normal methods.


No.
 
Gerald Davis
Ranch Hand
Posts: 872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If have an intention in do Procedural Programming you could come across more performance an memory hits then using objects. Static methods uses stack (call by value) objects us heap(call by reference).

I do know that I recursive use of static method or function can eat up memory , unless the compiler is optimized for it .
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Design considerations are much more important when deciding between static, and instance methods. Why do you ask the question? Even, if there is a difference in memory usage between the two approaches I suspect it is minimal and you will find better ways to optimize memory in other ways.
 
siva prakash
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

thanks for ur replies, can u give me a brief about situationswhere we go for static methods.





With Regards,
Siva
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you look at API, you'l find some classes that uses static methods along with non static ones: Color class, for example

Math class has all methods declared static
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic