From: Arno P. <ar...@pu...> - 2013-02-22 18:23:58
|
that will cause a problem. The GC only knows about global variables and memory that has been allocated with GC_MALLOC(). The 'notes' reference is part of an ObjC object that was allocated via alloc/init so the GC does not know about it, i.e., it will think that 'notes' can be collected. You need to store a reference to notes in some memory area that the GC knows about. We do this via the 'retain' policy in advisor.xml. One way you can do this is to declare a global variable that you initialize to a cross-compiled ArrayList and then add the reference to notes to this ArrayList. This is essentially what the retain policy does. As I mentioned, this gets pretty complicated. :) Arno On 2/22/13 9:40 AM, Steve Hannah wrote: > Thanks for the reply, Arno. The paper you sent me was quite helpful > on this subject also. Both here, and in the paper, you talk about > wrapping Objective-C objects with GC managed objects. I'm curious > about the inverse situation, where you are wrapping GC managed objects > with Objective-C objects. > > E.g. consider this class definition: > > // > // ViewController.h > // XcodeGUIApp > // > // Created by Steve Hannah on 2013-02-20. > // Copyright (c) 2013 Web Lite Solutions. All rights reserved. > // > > #import <UIKit/UIKit.h> > #import "xmlvm.h" > > @interface NotesListController : UIViewController > <UITableViewDataSource, UITableViewDelegate> > @property (retain, nonatomic) IBOutlet UITableView *tableView; > @property JAVA_OBJECT notes; > -(void)refreshNotes; > -(void)viewDidAppear:(BOOL)animated; > -(void)tableView:(UITableView *)tableView > didSelectRowAtIndexPath:(NSIndexPath *)indexPath; > @end > > (In particular, notice the > @property JAVA_OBJECT notes; > ) > > Then at some point the "notes" property is set like this: > > self.notes = ca_weblite_crossmobile_shared_Note_getNotes__(); > > Do I need to do anything special to let the GC know that the > JAVA_OBJECT is being "used" in this structure? I.e. is there a chance > that the GC will free the notes object while the Objective-C class > still needs it? > > Thanks again for all your help. > > -Steve > > > > > On Thu, Feb 21, 2013 at 10:30 PM, Arno Puder <ar...@pu...> wrote: >> >> this is an extremely tricky subject. Yes, you have to be very careful >> when mixing the two memory management models. I can only barely scratch >> the surface but, in essence, the cross-compiled Java version of NSObject >> becomes a wrapper around the native instance to an NSObject. When the GC >> reclaims the cross-compiled NSObject, it will call a finalizer >> (essentially overriding Object.finalize()) that will delegate the >> release to the wrapped Objective-C instance. But as I said, it gets a >> lot more complicated: associations between objects (e.g. >> UIView.subviews) and delegates need special attention. >> >> Arno >> >> >> On 2/21/13 7:49 PM, Steve Hannah wrote: >>> I'm experimenting using XMLVM to compile business logic, which I then >>> use inside a Cocoa GUI app - built with Xcode. I am trying to get an >>> understanding of the implications of XMLVM's garbage collected >>> pointers used together with objective-c objects. >>> >>> This page <http://www.hpl.hp.com/personal/Hans_Boehm/gc/simple_example.html> >>> says: >>> "It is usually best not to mix garbage-collected allocation with the >>> system malloc-free. If you do, you need to be careful not to store >>> pointers to the garbage-collected heap in memory allocated with the >>> system malloc." >>> >>> Does this mean that I shouldn't be storing JAVA_OBJECTs as properties >>> of objective-c classes? Are there any best practices that should be >>> followed here? >>> >>> Thanks for any tips. >>> >>> -Steve >>> >>> ------------------------------------------------------------------------------ >>> Everyone hates slow websites. So do we. >>> Make your web apps faster with AppDynamics >>> Download AppDynamics Lite for free today: >>> http://p.sf.net/sfu/appdyn_d2d_feb >>> _______________________________________________ >>> xmlvm-users mailing list >>> xml...@li... >>> https://lists.sourceforge.net/lists/listinfo/xmlvm-users >>> >> >> ------------------------------------------------------------------------------ >> Everyone hates slow websites. So do we. >> Make your web apps faster with AppDynamics >> Download AppDynamics Lite for free today: >> http://p.sf.net/sfu/appdyn_d2d_feb >> _______________________________________________ >> xmlvm-users mailing list >> xml...@li... >> https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > > |