OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

iOS: texture memory not released


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum]
View previous topic :: View next topic  
Author Message
a.terenzi
Appreciator


Joined: 03 Sep 2009
Posts: 227

PostPosted: Tue Dec 16, 2014 10:57 am    Post subject:
iOS: texture memory not released
Reply with quote

Sorry, I moved the post to here:

http://forum.openscenegraph.org/viewtopic.php?p=62075#62075

Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Tue Dec 16, 2014 2:55 pm    Post subject:
iOS: texture memory not released
Reply with quote

HI Alessandro,


I don't know enough about your application to know what is going on, but in general I can say that you cannot delete OpenGL objects from any other thread other than thread that has the context that owns the OpenGL objects.   To cope with the OpenGL limitation the OSG has to place all OpenGL objects associated with scene graph objects like osg::Texture2D etc. onto a pool of orphaned OpenGL texture objects that are not deleted right away, instead are left waiting to be deleted by the appropriate graphics thread.


The OSG viewer actually automatically can reuse or delete  that orphaned OpenGL texture objects during the normal frame.  How rapidly objects in the pool are deleted will depend upon the settings used.  I wouldn't worry unless you are specifically having a memory issue, these objects will get cleaned up by the OSG over time or when the graphics context gets deleted.

So... it's likely the "leak" is nothing of the sort, just this pool helping your application by preventing crashes that would occur if GL objects were deleted by the wrong threads.


Robert.


On 16 December 2014 at 10:57, Alessandro Terenzi < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi,
I've noticed that when I load a model with a texture and then dismiss the ViewController that displays that model, even though I correctly release it's memory (I'm tracing reference counts and I see that they always are 0 when the ViewController is dismissed), all the memory related to textures is still allocated. Anyone having this same issue? Moreover, it looks like that the same texture is allocated several times (2 or 4 depending on the plugin I use to load a model, for instance using fbx I see a couple of allocations while when using obj I see 4 allocations...and every single one remains allocated).

I'm using OSG 3.2.0, iOS SDK (as well as iOS itself) is 7 or 8 and tried with both Xcode 5.1.1 and Xcode 6. Don't know if this could be meaningful but I built OSG and my app with these compiler settings:

C Language Dialect: compiler-default
C++ Language Dialect: compiler-default
C++ Standard Library: libstdc++

I am attaching a couple of stack traces captured using Instruments and related to the same run/same snapshot.

Thank you for your help.
Alessandro

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=62071#62071




Attachments:
http://forum.openscenegraph.org//files/screenshot2_110.png
http://forum.openscenegraph.org//files/screenshot1_593.png


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi
Appreciator


Joined: 03 Sep 2009
Posts: 227

PostPosted: Wed Dec 17, 2014 9:34 am    Post subject:
Reply with quote

Hi Robert,
thank you for your answer, I guess that what you have talked about is exactly what is happening in my case.

Indeed, I tried to 'manually' release the textured objects while the rendering loop is still active and I assured that this happened in the same thread that created the OpenGL context: in this case everything is freed as expected and in a very short time.

Now I have to figure out why this does not happen when I 'dealloc' the view controller that originally created the rendering context (I'm releaseing OSG stuff in the 'destructor' of the view controller), I guess that this may be related to the fact that the 'dealloc' operation actually happens in a different thread (need to check this), so even though I release the scene graph and the viewer, all those OpenGL objects are kept in memory (as you said). Provided that I will free all resources in the right thread, is there a way (API) to force the viewer to delete that orphaned OpenGL texture object or this can happen only automatically?

Cheers,
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Wed Dec 17, 2014 10:02 am    Post subject:
iOS: texture memory not released
Reply with quote

HI Alessandro,

On 17 December 2014 at 09:34, Alessandro Terenzi < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Provided that I will free all resources in the right thread, is there a way (API) to force the viewer to delete that orphaned OpenGL texture object or this can happen only automatically?


In the include/osg/GLObjects header you'll find the function:

   /** Do a GL delete all OpenGL objects.
     * Note, must be called from a thread which has current the graphics context associated with contextID. */
   extern OSG_EXPORT void deleteAllGLObjects(unsigned int contextID);


You'll need to call this from the thread that has graphics context that your are cleaning up current.


If you've already deleted the context then you can use:

   /** Discard all OpenGL objects.
     * Note, unlike deleteAllGLjects discard does not
     * do any OpenGL calls so can be called from any thread, but as a consequence it
     * also doesn't remove the associated OpenGL resource so discard should only be
     * called when the associated graphics context is being/has been closed. */
   extern OSG_EXPORT void discardAllGLObjects(unsigned int contextID);


 To clean up the pool that OSG has used to track the GL objects that have been cached ready for cleanup/reuse - this prevents any of these objects being reuse inappropriately if you recreate a new graphics context and use the same contextID as well as just freeing up memory.


In normal OSG viewer usage you won't need to do either of these calls as osgViewer will do it for you.


Robert.



 

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi
Appreciator


Joined: 03 Sep 2009
Posts: 227

PostPosted: Wed Dec 17, 2014 9:42 pm    Post subject:
Reply with quote

Thank you Robert,
I will try to understand if I really need to use those methods or if I manage to let the viewer do all the cleanup as it is supposed to do.

Cheers,
Alessandro
Back to top
View user's profile Send private message
a.terenzi
Appreciator


Joined: 03 Sep 2009
Posts: 227

PostPosted: Sat Dec 20, 2014 9:26 pm    Post subject:
Reply with quote

Hi again,
unfortunately I was wrong, I still experience the same problem. Furthermore, I managed to reproduce it even in the very simple case where I just create a osg::Image object (loading it from disk) and releasing it immediately: the memory does not get deallocated even though the image reference's count is correctly set to 0.

Note: the problem happens even if I do not create any viewer and do not create any OpenGL context, I am just loading an image from disk into an osg::Image object.

Any suggestion?

Thanks.
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Sun Dec 21, 2014 2:47 pm    Post subject:
iOS: texture memory not released
Reply with quote

Hi Alessandro,

On 20 December 2014 at 21:26, Alessandro Terenzi < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi again,
unfortunately I was wrong, I still experience the same problem. Furthermore, I managed to reproduce it even in the very simple case where I just create a osg::Image object (loading it from disk) and releasing it immediately: the memory does not get deallocated even though the image reference's count is correctly set to 0.

Note: the problem happens even if I do not create any viewer and do not create any OpenGL context, I am just loading an image from disk into an osg::Image object.

Any suggestion?


Have a look at the plugin that is loading the data, under OSX/iOS there are various Mac specific plugins for loading images and video, because that's the way under Apples platform specific world.  It could be one of these plugins or the Apple library used to do the loading is leaking, OR simply the tool you are using to detect leaks is generating false positives.


One possibility to try would be to use the normal image plugins used on all other platforms such as tif, jpeg etc. these require additionality 3rd Party libraries though.

Robert.

 

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi
Appreciator


Joined: 03 Sep 2009
Posts: 227

PostPosted: Sun Dec 21, 2014 7:45 pm    Post subject:
Reply with quote

Hi again,
I've done other tests and I think that the problem is not just related to Image but to the Referenced class in general, because in my last test I just derived a simple class from Referenced, added a member variable to my ViewController like this:

osg::ref_ptr<MyReferencedClass> test_obj;

then I instantiated test_obj and when I release it, its destructor is never called (even though the reference count is set to 0 and the test_obj seems to be not valid anymore).

Moreover, if I use just simple pointers, like this:

MyReferencedClass* test_obj_2;

then it's destructor is called. So, to my understanding, the problem happens only when using ref_ptr.

I have searched the Internet for something ObjectiveC 's specific, and found that there exist a compiler option GCC_OBJC_CALL_CXX_CDTORS that should/can be used to ask the OBJ-C code to call Cxx destructors, but actually it seems not to make any difference in my case.

I am quite sure that it is something that depends on the compiler options or some Xcode settings, I use to use OSG from iOS SDK 4 and never had such an issue, I am experiencing it now with iOS SDK 7 and 8.

Thanks
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Sun Dec 21, 2014 7:53 pm    Post subject:
iOS: texture memory not released
Reply with quote

Hi Alessandro,


You don't say how you "release" test_obj, so it's not possible for us to know whether you've one something odd.  


ref_ptr<> when it goes out of scope calls unref() on the referenced object.


Referenced::unref() will in turn call delete on the object when the reference count goes to zero.


Now if all of this is happening but the compiler is neglecting to call to destructor then the compiling/linking has f*cked up big time and this little problem with be the least of your worries.


Others are getting on OK on OSX and iOS so I'd suspect something specific with your setup or your interpretation of the results.

Robert.






On 21 December 2014 at 19:45, Alessandro Terenzi < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi again,
I've done other tests and I think that the problem is not just related to Image but to the Referenced class in general, because in my last test I just derived a simple class from Referenced, added a member variable to my ViewController like this:

osg::ref_ptr<MyReferencedClass> test_obj;

then I instantiated test_obj and when I release it, its destructor is never called (even though the reference count is set to 0 and the test_obj seems to be not valid anymore).

Moreover, if I use just simple pointers, like this:

MyReferencedClass* test_obj_2;

then it's destructor is called. So, to my understanding, the problem happens only when using ref_ptr.

I have searched the Internet for something ObjectiveC 's specific, and found that there exist a compiler option GCC_OBJC_CALL_CXX_CDTORS that should/can be used to ask the OBJ-C code to call Cxx destructors, but actually it seems not to make any difference in my case.

I am quite sure that it is something that depends on the compiler options or some Xcode settings, I use to use OSG from iOS SDK 4 and never had such an issue, I am experiencing it now with iOS SDK 7 and 8.

Thanks
Alessandro

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=62154#62154





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi
Appreciator


Joined: 03 Sep 2009
Posts: 227

PostPosted: Sun Dec 21, 2014 8:23 pm    Post subject:
Reply with quote

The problem was exactly in the way I was releasing test_obj, I misunderstood the ref_ptr::release() semantic (my fault, sorry) but now that I had a second look at its implementation I saw that it calls unref_nodelete() and not unref() and that wrong assumption of mine lead to memory leaks.

Thank you anyway for all the info and suggestions provided so far.
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Mon Dec 22, 2014 8:49 am    Post subject:
iOS: texture memory not released
Reply with quote

Hi Alessandro,

On 21 December 2014 at 20:23, Alessandro Terenzi < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
The problem was exactly in the way I was releasing test_obj, I misunderstood the ref_ptr::release() semantic (my fault, sorry) but now that I had a second look at its implementation I saw that it calls unref_nodelete() and not unref() and that wrong assumption of mine lead to memory leaks.

Thank you anyway for all the info and suggestions provided so far.


Glad to hear you've got to the bottom of the issue.



I had thought ref_ptr<>::release() would had a doxygen comment explaining how it works and it's usage but on just checking now I've seen that it doesn't so I've added a short explanation and checked this into svn/trunk and OSG-3.2 branch.

 

Robert.

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi
Appreciator


Joined: 03 Sep 2009
Posts: 227

PostPosted: Tue Dec 23, 2014 11:55 am    Post subject:
Reply with quote

Hi Robert,
thank you for updating the documentation.

As mentioned earlier I was using release() where I was not supposed to, anyway after having updated my code I noticed that there is a potential issue related to some memory not being released by the osgdb_fbx plugin... specifically I noticed that when the plugin loads a file it first sets the CACHE_IMAGES option.

To my understanding this makes the osgDB::Registry instance to keep references to loaded images contained in the FBX file. The problem is that it seems that the fbx plugin seems not to clean the registry cache (even when it is not used anymore), so my question is: is the fbx plugin supposed to clean the cache after it has done its job or this task is supposed to be done 'manually/explicitly ' by the user?

Or in general, when the registry cache is supposed to be cleaned? Is the viewer in charge of cleaning the registry's cache when it has done?

Thanks.
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10908

PostPosted: Tue Dec 23, 2014 12:07 pm    Post subject:
iOS: texture memory not released
Reply with quote

HI Allessandro,

On 23 December 2014 at 11:56, Alessandro Terenzi < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Robert,
thank you for updating the documentation.

As mentioned earlier I was using release() where I was not supposed to, anyway after having updated my code I noticed that there is a potential issue related to some memory not being released by the osgdb_fbx plugin... specifically I noticed that when the plugin loads a file it first sets the CACHE_IMAGES option.

To my understanding this makes the osgDB::Registry instance to keep references to loaded images contained in the FBX file. The problem is that it seems that the fbx plugin seems not to clean the registry cache (even when it is not used anymore), so my question is: is the fbx plugin supposed to clean the cache after it has done its job or this task is supposed to be done 'manually/explicitly ' by the user?


For general usage it would probably be appropriate for fbx plugin to share images rather than load separate instances.  Leaving objects in the cache isn't a memory leak as the cache can be cleaned up.


Quote:
Or in general, when the registry cache is supposed to be cleaned? Is the viewer in charge of cleaning the registry's cache when it has done?


The Registry ObjectCache has a default time that objects remain in the cache after which they will be removed from the cache if they aren't otherwise being used in the scene graph.  You can explictly clear the cache too if you so wish.


For embedded usage one typically will use native plugins for loading and saving data rather than using plugins like fbx which have a big payload in terms of 3rd part libraries and run-time memory usage.

Robert.

 

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Render to texture with GL3. Raizel General 3 Tue May 23, 2017 10:33 am View latest post
No new posts How to replace the texture data in th... xdfanfan General 1 Wed Apr 05, 2017 12:44 pm View latest post
No new posts 3rdParty package precompiled with Vis... zonk Announcement [ANN] 0 Wed Mar 22, 2017 3:51 pm View latest post
No new posts Multitexture: projection a texture on... Ekaterina General 2 Mon Feb 06, 2017 1:48 pm View latest post
No new posts Free Android game based on OSG & ... kornerr Announcement [ANN] 1 Fri Feb 03, 2017 1:56 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP