Is it allowed for unused variables to be optimized away by the compiler?

Let's assume I have the following code:
public void myMethod() {
   final Object x = new Object();
   // I never refer to x.
   // other code, for example:
   System.out.println("lala");
}The question I have is: what is the earliest possible moment that x can be garbage collected?
I have checked the JLS and JVM spec, but I cannot find the answer. It seems to me, that the assignment to x causes a local variable slot in the stack frame to be assigned a reference to x, and therefore, x cannot be garbage collected until after the method returns since there is a strong reference to x during the entire method call. But maybe the compiler might be allowed to compile away the unused local variable, resulting simply in the code: new Object(), which would then create an object which immediately has no strong references, and can be collected before the println. Does anybody know the correct answer?
Regards,
Sebastiaan

sebster wrote:
On what do you base this assertion? Do you have any references?The problem is that I can't remember if I read it in a document related to garbage collection or if it was in the VM specification (the language specification does not specify that a GC must exist if I remember it correctly).
One thing that shows what I told you currently is true is that this code:
public class ByteCode {
    public void myMethod() {
        final Object x = new Object();
        System.out.println("lala");
}Compiles into this using the Sun compiler for Java 6.
public ByteCode();
  Code:
   Stack=1, Locals=1, Args_size=1
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return
  LineNumberTable:
   line 21: 0
public void myMethod();
  Code:
   Stack=2, Locals=2, Args_size=1
   0:   new     #2; //class java/lang/Object
   3:   dup
   4:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   7:   astore_1
   8:   getstatic       #3; //Field java/lang/System.out:Ljava/io/PrintStream;
   11:  ldc     #4; //String lala
   13:  invokevirtual   #5; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
   16:  return
  LineNumberTable:
   line 23: 0
   line 25: 8
   line 27: 16
}Note the call to astore_1 that is the assignment to the local variable.
Kaj
Ps. looks like the forum has a bug in the handling of the pre tag. :(
Edited by: kajbj on Feb 14, 2008 5:09 PM

Similar Messages

  • Document scanning software that allows for custom search fields, attaching a thumbnail to the scanned document file, and works with any scanner?

    I am a professional photographer, with years of paper model releases. I would like to find a document scanning software that works with my exisiting flatbed scanner (Canon MP250) that I can customize the seach fields for (ie. name, agency, job, etc.) and also attach a thumbnail image to as a job reference. I would like the document to be searchable as well. I've looked at a few different document scanning software companies, but I haven't found one that allows me to attach a jpeg file to a scanned PDF. Does anyone know if software like this exists?

    You can't do better than to use VueScan:
    http://hamrick.com/

  • A Pebble app that allows for voting up/down as well as advancing the track (no prev in radio mode)

    Pebble is touting that with the release of their new "Pebble App Store", happening soon out now, Pandora will have an app that runs on the Pebble allowing you to vote a track up/down as well as advance to the next song.  As I subscribe to Spotify and not Pandora, I would LOVE to see this same kind of app coming from Spotify.  Currently, the Pebble can control your music, but only through the "now playing" system on a given smartphone.  Personally, I have an iPhone 5 and while it works flawlessly to play/pause and advance tracks, having the voting up/down functionality in an actual Spotify app would be amazing.
    EDIT: The app store is open, but Pandora have not released their app for some reason.  Perhaps they are waiting for the official release of the Steel (I know the promo units had it pre-loaded for reviewers).  I think it would be very interesting if Spotify were to beat them to it!  There are several other apps from major companies, like Yelp and Foursquare, so this isn't just a niche market.  Other companies are realizing the potential, and I'd be really excited if Spotify did, too!
    The attached image is from a review on tomsguide.com showing Pandora's Pebble app as it will look while controlling the smartphone it is linked to.  I think it's a very clean and simple interface that could easily be replicated by Spotify.  The two services, while streaming radio, are very similar.  For those of us using Pebble I think it may be tempting to switch without this feature, which is the main reason I have brought this to the ideas forum.

    Already created a new idea, but as this already exists, I'll add my UI ideas here too :)
    My idea:
    Multiple UIs, accessible via a long press of the middle button. There you can choose the screen:
    Playback screen:
    - up and down will skip tracks while holding them will search in track.
    - middle is play/pause
    On Volume screen up and down will adjust volume instead of back/forward.
    Rating screen:
    - Up and down will rate the track while listening to Radio, if listening to playlist they will toggle shuffle/loop
    - middle will (un)star the current track.
    Playlist selector
    - Browse through your playlists and tracks
    - middle button to open playlist/play selected track, hold to get options: play next, play radio based on selection, hide (which will hide the selector and go back to last used screen); back navigation with back button.
    Copied from http://community.spotify.com/t5/Spotify-Ideas/Pebble-Integration/idi-p/686194

  • I created an allowance for my daughter but can't get past the edit Apple ID details. I get Your information could not be saved at this time.

    I had to create an account for her because she is underage but I can't get past the edit Apple ID details page. I have confirmed the email address and was able to set up some of the services on the iPod but can't finish setting up the account.

    I'm experiencing the very same thing.  I assumed that the site was down, but it looks like there are multitudes of complaints about this.  What's up Apple?  I can't seem to find an answer to this online...  Thanks!

  • How can we fine and delete unused variables?

    Hi , This is Kumar,
    I have been working for some Upgrade project. My manager asked me the way  to know unused variables which are already declared in the program . But i don't know any special way to find them.
    Normally for Internal tables we are using CLEAR, REFRESH AND FREE.
    So,
    How can we delete unused variables which are already declared in  program?
    If anybody have any idea , kindly let me know.
    Thanks & Regards,
    P.N.Kumar.

    Hello friend,
    in SE24,SE38 and SE80 there is a menu called "Refactoring" which can enable you to delete unused variable defined in your source code automatically.
    Of course it is not the only functionality of this poweful tool. Please read the article below:
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/2054857b-1b4d-2c10-f7a5-d283a11f6789
    I am sure you can benefit a lot from it not only know how to delete unused variable
    Best Regards,
    Jerry

  • Set a value for a variable of type exit

    Hello,
    I am filling some variables with multiple values in user exit.
    Now, i would like to place some of these characteritics in Header area. It's of course impossible because there is multiple values but ...
    I will put dropdown box in the web application for these chars. The problem is that by default, any value is assigned to the dropdwom ( any variable value is set).
    Do you know how i can set a value for theses variable after filling all values by the user exit. SO that only one value is selected for the header and all others values available in the dropdown ?
    Regards,
    Jarod

    Hi,
    Off late, this seems to be a usual requirement.
    Just create a Z program to call the FM API_SEMBPS_VARIABLE_SET and then call the FM API_SEMBPS_POST.
    you should be preparing the content/set value to pass to the FMs. check the whereused list to see how this FMs can be used/called.
    finally, run this program for your variable, after the loading/filling the exit variable. Please note that to set 'exit' variables, the sourcing variable's content need to be read/set first before setting the exit varible.
    HTH,
    Regards,
    Nataraj.

  • Adcfgclone.pl dbTier is not prompting for ORACLE_HOME variable

    hi,
    adcfgclone.pl is not prompting for ORACLE_HOME variable.
    and erroring out with
    Checking the port pool 12
    done: Port Pool 12 is free
    Report file located at /appsutil/out/portpool.lst
    RC-00203: Unable to create/write to file /appsutil/out/portpool.lst.
    Complete port information available at /appsutil/out/portpool.lst
    RC-50004: Error occurred in CloneContext:
    AC-00005: No write permissions for creating the Context file - /appsutil/temp.xml
    Raised by oracle.apps.ad.context.AppsContext
    Check Clone Context logfile /mnt/ebs/PTCH/bin/db/tech_st/12.1.0/appsutil/clone/bin/CloneContext_0421032159.log for details.
    ERROR: Context creation not completed successfully.
    For additional details review the file /tmp/adcfgclone_6999.err if present.
    DOC refrred: How To Quick Solve This Post Clone Error : RC-50004, AC-00005: No Write Permissions For Creating The Context file - /tmp/temp.xml ? (Doc ID 842948.1)
    in the above DOC please let me know how to perform ANALYSIS part..
    Database version: 12.1.0.2.0
    Applications version: 12.1.3
    OS                         : OEL6.4
    please suggest
    Thanks
    Raghavendra

    are you able to create a file with os user which is running the rapidclone in /appsutil/temp.xml
    please check and update
    use touch command to create a file
    did you gave correct oracle home when prompted by rapidclone ?
    If you have set the right permissions at /tmp and the problem remains then check if at the post cloning steps at the dbTier, the scripts asks for the "Oracle Database Home"
    Target System RDBMS ORACLE_HOME Directory [/u01/clone/db/11.2.0/] :
    post the output of below command
    $ls -ltr ( in appsutil folder )
    AppsMasti
    sharing is Caring

  • Can anyone explain with senairio for formula variables with replacement  pa

    can anyone explain with senairio for formula variables with replacement  path?

    See the below link
    An Example for Replacement path
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
    Document Count using Replacement path
    I've explained the steps in this thread.
    Query formula-Counter???
    Example for Replacement Path: Characteristic Variable.
    http://help.sap.com/saphelp_nw04/helpdata/en/2c/78a03c1178ad2ce10000000a114084/content.htm
    Variable Replacement Example
    http://help.sap.com/saphelp_nw04/helpdata/en/af/809528939d5b4fbff7e16a5bdc0d85/content.htm
    Formula Variable.
    http://help.sap.com/saphelp_nw04/helpdata/en/ca/5f9ac61a205a459d0e7ef313d10321/content.htm
    Regs
    Gopi
    Assign points if it helps

  • Capacities of type 1 or 2 are only allowed for resources

    HI,
    I am getting the below error during selecting the capacity catogory 001 in the Capacities tab in CR01 transaction.
    Capacities of type 1 or 2 are only allowed for resources.
    Thanks and regards
    Murugesan

    WHat is the work center category you are creating...

  • Posting in foreign currency not allowed for external tax system

    Hello all,
    I created a purchase order for inter-company stock transfer. Then created a corresponding outbound delivery and goods issue using  VL10h and completed goods issue. Then I completed good receipt using MIGO. When I was trying to create a sales order I got this message "Posting in foreign currency not allowed for external tax system". What could be the reasons for this message.  The message number said FS885.
    One final note. I am able to create Billing document with manual batch number input in Delivery document item. But when I am using Batch split I am not able to generate invoice. Can anyone tell me what could be the problem here.

    Hi Samir,
    The Goods Received NI (Allocation Cost Account) need to be balaned in Local and System Currency as this is a Multi Currency account and these are the currencies that Business One will offer reports in.
    The Foreign Currency for this account is irrelevant as you can never get a balance in FC for a multi currency account, neither will you find any reports for this. 
    If the client insists you can create a manual Journal entry in FC only to correct this. Business One does not offer any functionality to correct the Foreign Currency in this scenario. (like Exchange Rate difference for Local Currency and Conversion Differences for System Currency)
    To do the manual JE open the form settings and the tab 'table', here untick the box 'From FC Field'. This will enable you to create a FC JE only.
    Hope it clarifies the issue.
    Jesper

  • How do i allow for a discount code or other discount on my form?

    How do allow for a discount code or other discount on the form?

    I am assuming you want to use paypal with this form which mean you need to use an HTML form. Unfortunately Formscentral doesn't support calculations with HTML forms. This is going to make discounts difficult. Depending on your exact needs you might be able to get away with using different fields for the discount. Example. Item one is standard room rate. Item two might be the same room with a AAA discount applied. etc. You will have to play with it to see if you can get it to do what you want.
    Andrew

  • How many concurrent users are allowed for an Azure Virtual Machine?

    How many concurrent users are allowed for an Azure Virtual Machine?
    Please share the details with the Azure VM size. Currently I have Standard VM of size D13(4 cores, 28GB RAM)

    Hi SanPSK,
    Thanks for posting here.
    I suggest you to check this article for Azure VM size
    https://msdn.microsoft.com/en-us/library/azure/dn197896.aspx
    For the concurrent users on VM - A maximum of 2 concurrent connections are supported, unless the server is configured as a Remote Desktop Services session host.
    Girish Prajwal

  • Error: "Variable State has been used outside the reusable components"

    When I open a query in the ad hoc query designer I get several error messages like "Variable State has been used outside the reusable components."  I don't what this means or how to fix it.
    "State" is one of the variables used.  And there is a error for every variable that is used.
    All the variables are in the free characteristics.
    When I open the query in Query Designer, it is ok.
    Any ideas?

    Hi Fong,
    PLease check the following link:
    http://help.sap.com/saphelp_nw04/helpdata/en/1f/03223c5f00612be10000000a11402f/content.htm
    It states that:
    You cannot integrate variables into the query directly.
    However, you can use variables in reusable structures, or restricted or calculate key figures, which are used in the Ad-hoc Query Designer
    Hope this helps...

  • Looking for a recessed computer desk that will fit the iMac 27

    I have the iMac 27 computer.  The monitor sits high on a regular desk requiring more upgaze than is typically comfortable for the eyes.  I have been researching recessed computer desks but so far they seem limited to the iMac 24 or smaller. 
    Was wondering if anyone has found a recessed-type desk or some such variation that allows for more comfortable viewing angle.

    In addition to the excellent suggestions by Paul......
    I have the XP 400.  For your other products to work wireless w/the printer, you should also do the wireless set-up through the printer.  The printer will run a diagnostic test run printout for you.  Assuming that your model 410 works the same as mine.  The printer's user manual should also help you with your wireless setup as it has several options.
    Last resort is to contact Epson and/or their tech support website.

  • Java.sql.BatchUpdateException: ORA-01027: bind variables not allowed for da

    Hi guys, I m facing a problem while executing below query .Query is working fine in toad i don't know what is the issue with the code
    <code>
    String url3 = "CREATE OR REPLACE VIEW Table2(PERIOD, YEARS, COST_CENTRE, S_DIR_PERM, S_DIR_CONT, S_INDIR_PERM, S_INDIR_CONT, O_DIR_PERM, O_DIR_CONT, O_INDIR_PERM, O_INDIR_CONT)AS select period, year, cost_center, sum(s_dir_perm), sum(s_dir_cont), sum(s_indir_perm), sum(s_indir_cont), sum(o_dir_perm), sum(o_dir_cont), sum(o_indir_perm), sum(o_indir_cont) from ( select b.period, b.year, a.cost_center, sum(a.perm_dir_hc) as s_dir_perm, sum(a.contract_dir_hc) as s_dir_cont, sum(a.perm_indir_hc) as s_indir_perm, sum(a.contract_indir_hc) as s_indir_cont, 0 as o_dir_perm, 0 as o_dir_cont, 0 as o_indir_perm, 0 as o_indir_cont from ZVHR_ACT_HC_ASOF_FISPRD a, pertable b where to_char(as_of_date, 'mm/dd/yyyy') = b.ENDPERIOD and shift not in ('G','N','O2','O7') and b.endperiod = ? group by b.period, b.year, a.cost_center union select b.period, b.year, a.cost_center, 0 as s_dir_perm, 0 as s_dir_cont, 0 as s_indir_perm, 0 as s_indir_cont, sum(a.perm_dir_hc) as o_dir_perm, sum(a.contract_dir_hc) as o_dir_cont, sum(a.perm_indir_hc) as o_indir_perm, sum(a.contract_indir_hc) as o_indir_cont from ZVHR_ACT_HC_ASOF_FISPRD a, pertable b where to_char(as_of_date, 'mm/dd/yyyy') = b.ENDPERIOD and shift in ('G','N','O2','O7') and b.endperiod = ? group by b.period, b.year, a.cost_center) group by period, year, cost_center";
    PreparedStatement statement3 = connection.prepareStatement(url3);
    statement3.setString(1, "12/10/2008");
    statement3.setString(2, "12/10/2008");
    statement3.addBatch();
    statement3.executeBatch();
    </code>
    i m getting the following error
    java.sql.BatchUpdateException: ORA-01027: bind variables not allowed for data definition operations
    can any1 help me with this.

    Can you explain what you are trying to do from a business perspective?
    If you are creating a view, it doesn't make sense to pass bind variables to that DDL statement. The view definition itself is going to have to end up with hard coded date values there. So what possible benefit is there to using bind variables?
    As an aside, if you are using bind variables and you have DATE columns, you really want to pass in the proper data type (i.e. setDate or setTimestamp rather than setString). Otherwise, Oracle has to do implicit string to date conversion, which depends on the session's NLS settings, which is likely to be different on different client machines and lead to all sorts of odd errors and behaviors down the line.
    Are you trying to build a view that takes parameters? If so, there are a few options for that sort of thing.
    Justin

Maybe you are looking for

  • Report for Qty Receipt values ( O.K qty only )

    Hi experts, I received 100 qty , Value Rs.100 thru tcode MIGO, movt type 101.  But later on out of 100 qty, 50 qty got rejected thru tcode QA32.  The value appearing in MB51 report is Rs. 100.  Is there any report in standard SAP where value for O.K

  • Can a web service query a database at set intervals?

    Can someone verify if this is feasible? I need to display live data via browsers .  I would like to have the query to the database executed server side and have the web service provide the data to the browsers. Here is what I propose : I would like t

  • Webservice sender and Receiver. Pls advice urgent

    Hi All, My Scenario System A (WebService) -- XI -- System B (WebService) Pls let me know 1. What does it mean by WebService needs WebServer? 2. For System A (WebService) -- XI     Do I require WebServer to be installed at System A or XI? 3. For XI --

  • "change" button is not visible in check status ?

    HI, We are under upgrade of SRM 4.0 to SRM 5.0 . In SRM 4.0 "change" button is visible in check status even if shopping cart is under approval state. But in SRM 5.0 "change" button is not visible in check status if Shopping cart is under approval sta

  • IDVD 5 won't burn

    I have iDVD 5 (current with updates) on my iBook G4 and use a LaCie external CD/DVD burner. I followed Ken's steps in creating a slideshow, but when I get to the "burn" step, it won't do anything. The burn icon shows up, then closes and the program s