LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2007, 01:21 AM   #1
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Rep: Reputation: 15
Memory in Java


Hi, suppose you have the following local variable declaration:

Vector<ClassX> v = new Vector();

v holds an address that is stored in the heap, and that address is of something stored in the stack right? I just want to confirm my belief that new returns addresses stored in heap. The stuff held in those address are stored in the stack(if its a local var)

Is it the same way in C, except for malloc or calloc instead of new? Can someone point me to some easy tutorials with lots of diagrams on memory in Java and C please?
 
Old 10-06-2007, 03:47 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
The short answer is "it's implementation defined - depends on your JVM". If this were C++ code, it would be the perfect reverse of what you said. The reference v is stored on the stack, and it points to an object on the heap. However, as a garbage collecting language, it's not uncommon for JVM's to implement almost everything on the heap, so they could both be on the heap. Of course I'm not certain of this, I'm speaking from 3rd hand knowledge on the Java stuff, although I'm sure of the C/C++ stuff.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Linux Process memory footprint with and without -Xmx rolandofghent Linux - General 5 09-27-2007 09:08 AM
Java process memory space 32/64 Woody Benot Red Hat 0 06-06-2007 04:07 AM
Memory usage problem - Java MRMadhav Programming 16 07-20-2006 09:27 AM
Java - will this casue a memory leak? PhilD Programming 4 03-28-2003 05:38 PM
Java in FreeBSD : using too much memory ? tuanito *BSD 2 02-15-2003 08:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration