Memory leak within Media / MediaPlayer / MediaView
Hi,
I have a very simple program that plays 3 video one after another in a loop on Windows 7.
With visualvm I do not see the heap increasing, but with the Windows Task Manager the memory usage is growing rapidly. After an amount of hours the movieplayer stops playing movies.
I do not see anywhere where I can clean up.
Can anybody help me please?
The code is:
Media media = null;
MediaPlayer mediaPlayer = null;
MediaView mediaView1 = new MediaView();
private final MediaHandler mh;
static public Group root;
@Override
public void start(Stage stage)
root = new Group();
stage.setTitle("JavaFX test");
stage.setResizable(true);
stage.setFullScreen(true);
Scene scene = new Scene(root);
scene.setFill(Color.WHITE);
stage.setScene(scene);
stage.show();
mh = new MediaHandler();
mh.start();
public class MediaHandler extends Thread
public MediaHandler()
mediaView1.setX(0);
mediaView1.setY(0);
root.getChildren().add(mediaView1);
@Override
public void run()
synchronized (root)
do
createMediaplayer();
try
root.wait();
catch (InterruptedException e)
while (true);
* @param mediaPlayer
private void createMediaplayer()
mediaView1.setVisible(true);
if (media == null || media.getSource().equals(url1))
media = new Media(url2);
mediaPlayer = new MediaPlayer(media);
mediaPlayer.setCycleCount(1);
mediaPlayer.setAutoPlay(false);
mediaView1.setMediaPlayer(mediaPlayer);
mediaPlayer.play();
else if (media.getSource().equals(url2))
media = new Media(url3);
mediaPlayer = new MediaPlayer(media);
mediaPlayer.setCycleCount(1);
mediaPlayer.setAutoPlay(false);
mediaView1.setMediaPlayer(mediaPlayer);
mediaPlayer.play();
else
media = new Media(url1);
mediaPlayer = new MediaPlayer(media);
mediaPlayer.setCycleCount(1);
mediaPlayer.setAutoPlay(false);
mediaView1.setMediaPlayer(mediaPlayer);
mediaPlayer.play();
mediaPlayer.setOnEndOfMedia(new Runnable()
@Override
public void run()
synchronized (root)
root.notifyAll();
public static void main(String[] args)
launch(args);
Edited by: 975090 on 5-dec-2012 2:56
I found two issue in javaFx Jira:
http://javafx-jira.kenai.com/browse/RT-17879 Resolution: Unresolved Created: Nov, 9 2011 12:59 PM
http://javafx-jira.kenai.com/browse/RT-21050 Resolution: Unresolved Created: Apr, 20 2012 07:48 AM
Edited by: quitusl on 08/01/2013 18:34
Edited by: quitusl on 08/01/2013 18:35
Similar Messages
-
Memory leak within FOProcessor class
Hi all,
I'm trying to use the XML Publisher API (5.6.2 and 5.6.3) to generate PDF documents from XSL templates and XML data in a J2EE environment (Jboss 4.0.5) with Struts but a memory leak occurs.
It seems not to be a multithreading issue because the leak is there even if the PDF documents are generated one by one.
I made many tests to isolate the leak and I have simplified my code as much as possible: it seems to happen within the FOProcessor class.
One of the tests generates 4,500 PDF documents (one at a time) from an XML file (3 KB) and an XSL file (74 KB with blanks). Nothing else is done with the Jboss server during this test. The XSL file was created before the test from a RTF file with XML Publisher. The memory leak is around 70 KB for each PDF document (around 300 MB for the whole test).
As you can see below from the heap histogram (taken at end of test after a full garbage collection) it seems that the XSL and XML elements/attributes are not released (and thus never garbage collected).
Did I miss something or is there an actual problem with the XML/XSL parsing within the XML Publisher API?
Thanks for your help.Object Histogram:
Size Count Class description
131376968 2353450 java.lang.Object[]
60389464 937300 char[]
48260304 335141 oracle.xml.parser.v2.XSLResultElement
35690000 2230625 oracle.xml.util.FastVector
24127104 1005296 java.lang.String
16539120 413478 oracle.xml.parser.v2.XSLNode$AttrValueTmpl
14757064 128058 int[]
13348768 417149 java.lang.ref.Finalizer
12701776 102220 * ConstMethodKlass
12544808 23433 byte[]
12204080 108965 oracle.xml.parser.v2.XSLText
8344600 86584 java.util.Hashtable$Entry[]
7363768 102220 * MethodKlass
5592784 138700 * SymbolKlass
5362256 335141 oracle.xml.parser.v2.XSLAttributeSet[]
5267336 8135 * ConstantPoolKlass
5234016 163563 java.util.TreeMap$Entry
5121744 213406 java.util.Hashtable$Entry
4900480 61256 oracle.xml.parser.v2.XPathStep
4087120 51089 java.lang.reflect.Method
3823216 40276 java.util.HashMap$Entry[]
3524696 8135 * InstanceKlassKlass
3378000 84450 java.util.Hashtable
3064872 127703 java.util.HashMap$Entry
2971904 6880 * ConstantPoolCacheKlass
2968560 26505 oracle.xml.parser.v2.XSLValueOf
2770656 24738 oracle.xml.parser.v2.XSLVariable
2167520 27094 oracle.xml.parser.v2.XPathFunctionCall
1880088 33573 oracle.xml.parser.v2.PathExpr
1726360 61482 java.lang.String[]
1573720 39343 java.util.HashMap
1476576 30762 oracle.xml.parser.v2.XSLExprValue
1460840 36521 java.util.TreeMap
1319360 23560 oracle.xml.parser.v2.XPathConstantExpr
1054976 16484 org.jboss.mx.server.InvocationContext
1001264 3546 * MethodDataKlass
887424 11049 short[]
835680 8705 java.lang.Class
830208 25944 oracle.xml.util.NSNameImpl
705816 29409 java.util.ArrayList
684152 4501 org.jboss.web.tomcat.tc5.session.SessionBasedClusteredSession
670288 14071 java.lang.Object[]
640832 10013 oracle.xml.parser.v2.XPathVarReference
561056 35066 javax.management.modelmbean.DescriptorSupport
556272 23178 EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap$Entry
552984 30451 java.lang.Class[]
494760 2945 oracle.xml.parser.v2.XSLTemplate
480792 20033 antlr.ANTLRHashString
442576 27661 java.lang.Integer
432096 4501 org.jboss.web.tomcat.statistics.ReplicationStatistics$TimeStatistic
429040 10726 org.hibernate.hql.ast.tree.Node
369880 9247 javax.management.modelmbean.ModelMBeanOperationInfo
312384 19524 java.util.TreeMap$3
305368 5453 java.net.URL
287392 8981 org.jboss.mx.interceptor.ReflectedDispatcher
259264 338 EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap$Entry[]
252280 4505 org.jboss.cache.lock.ReadWriteLockWithUpgrade
238600 5965 org.jboss.mx.interceptor.PersistenceInterceptor
238600 5965 org.jboss.mx.interceptor.AttributeDispatcher
236616 9859 org.jboss.mx.server.AbstractMBeanInvoker$OperationKey
219776 3434 java.lang.reflect.Constructor
206880 6465 javax.management.modelmbean.ModelMBeanAttributeInfo
193168 2259 java.lang.reflect.Method[]
173184 5412 java.lang.ref.SoftReference
164920 589 oracle.xml.parser.v2.XSLStylesheet
164464 541 * ObjArrayKlassKlass
152832 6368 org.dom4j.tree.DefaultAttribute
149472 2076 java.lang.reflect.Field
144160 4505 org.jboss.cache.Node
143160 5965 org.jboss.mx.interceptor.ModelMBeanAttributeInterceptor
140600 3515 org.apache.xerces.dom.DeferredTextImpl
140224 2740 javax.management.modelmbean.ModelMBeanAttributeInfo[]
139056 7658 boolean[]
134664 3359 java.lang.String[][]
131936 1178 oracle.xml.parser.v2.XSLCondition
131936 1178 oracle.xml.parser.v2.XSLForEach
129072 2668 javax.management.modelmbean.ModelMBeanOperationInfo[]
128952 5373 EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap$Entry
124776 1733 org.hibernate.hql.ast.tree.IdentNode
115200 1800 javax.management.modelmbean.ModelMBeanInfoSupport
113088 2356 oracle.xml.parser.v2.AdditiveExpr
109416 4559 java.beans.PropertyChangeSupport
108960 1135 java.io.ObjectStreamClass
108120 4505 org.jboss.cache.lock.IdentityLock
105864 345 long[]
98752 3086 java.io.ObjectStreamClass$WeakClassKey
97968 4082 java.util.Vector
96672 2014 java.util.Properties
94240 589 oracle.xml.parser.v2.XSLOutput
90072 3753 javax.management.ObjectName$Property
87432 3643 javax.management.MBeanParameterInfo
82368 858 org.hibernate.hql.ast.tree.DotNode
81248 5078 java.lang.Long
78656 1229 org.hibernate.mapping.Column
77664 4854 java.util.Collections$SynchronizedSet
77448 3227 java.util.LinkedList$Entry
73824 769 org.jboss.mx.modelmbean.XMBean
73536 4596 java.util.Hashtable$KeySet
72144 4509 EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet
72144 4509 EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList
72144 4509 org.jboss.cache.Fqn
72080 4505 org.jboss.cache.lock.ReadWriteLockWithUpgrade$WriterLock
72080 4505 org.jboss.cache.lock.LockStrategyRepeatableRead
72080 4505 org.jboss.cache.lock.ReadWriteLockWithUpgrade$ReaderLock
72080 4505 org.jboss.cache.lock.LockMap
72016 4501 org.apache.catalina.session.StandardSessionFacade
71776 4486 java.io.FileDescriptor
70680 589 oracle.xml.parser.v2.XSLCallTemplate
70680 589 oracle.xml.parser.v2.XSLApplyTemplates
70224 154 org.hibernate.persister.entity.SingleTableEntityPersister
68296 2774 javax.management.ObjectName$Property[]
68160 1065 org.apache.xerces.dom.DeferredElementNSImpl
67760 770 org.hibernate.loader.entity.EntityLoader
66992 19 EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap$Entry[]
65968 1178 oracle.xml.parser.v2.XPathFilterExpr
65968 589 oracle.xml.parser.v2.XMLUTF8Reader
64432 4027 java.util.HashSet
63648 1326 oracle.xml.parser.v2.XMLNode[]
63440 1586 org.hibernate.loader.DefaultEntityAliases
61256 589 oracle.xml.parser.v2.XSLNode
61256 589 oracle.xml.parser.v2.XMLReader
60816 2534 org.apache.xerces.xni.QName
57360 478 org.hibernate.hql.ast.tree.FromElement
56976 1187 org.hibernate.mapping.Property
56544 1178 oracle.xml.parser.v2.XSLNodeSetExpr
56544 1178 oracle.xml.parser.v2.MultiplicativeExpr
56544 1178 oracle.xml.parser.v2.EqualExpr
54384 618 oracle.xml.parser.v2.XMLError
49392 2783 javax.management.MBeanParameterInfo[]
47648 1489 java.util.LinkedHashMap$Entry
47120 589 oracle.xml.parser.v2.XMLByteReader[]
... -
APEX 4.1.1 Memory Leak in IE7
Hi,
We busy upgrading our apex and db from 3.0/10G to 4.1.1/11.2G and notice that there appears to be a memory leak when using APEX. At one stage we have had IE7 using over a gig of memory.
When you load or refresh your page IE7 seems to grab on average 2-5MB of memory for each page load. At first we thought it may have been our apps or setup but this also happens when we go to app 4550 page 1 on apex.oracle.com.
How to replicate:
Open task manager to view the Memory Usage.
Using IE7
1. Go to http://apex.oracle.com/pls/apex/f?p=4550:1
2. Go back to Task Manager and note the readings once the CPU Usage for iexplore.exe has stablised to 0.
3. go back to IE7 and press F5
4. Repeat steps 2-3 and you will see the Memory usage increases.
We think this maybe due to a few jQuery UI memory leaks within IE7 and thought this bug ticket maybe of interest http://bugs.jqueryui.com/ticket/7666 (Slightly different versions but similiar experiences)
Could someone else confirm that they also experience the increasing or have had similiar problems and managed to resolve it?
TBH, it wouldn't be an issue to use another browser like Firefox to access the builder but this also affects the applications if they include APEX standard Javascript and CSS.
Thanking you in advance.
Alistair
Edited by: Alistair Laing on Jun 16, 2012 2:32 PM
Added TagsAlistair Laing wrote:
Hi,
We busy upgrading our apex and db from 3.0/10G to 4.1.1/11.2G and notice that there appears to be a memory leak when using APEX. At one stage we have had IE7 using over a gig of memory.
When you load or refresh your page IE7 seems to grab on average 2-5MB of memory for each page load. At first we thought it may have been our apps or setup but this also happens when we go to app 4550 page 1 on apex.oracle.com.
How to replicate:
Open task manager to view the Memory Usage.
Using IE7
1. Go to http://apex.oracle.com/pls/apex/f?p=4550:1
2. Go back to Task Manager and note the readings once the CPU Usage for iexplore.exe has stablised to 0.
3. go back to IE7 and press F5
4. Repeat steps 2-3 and you will see the Memory usage increases.
We think this maybe due to a few jQuery UI memory leaks within IE7 and thought this bug ticket maybe of interest http://bugs.jqueryui.com/ticket/7666 (Slightly different versions but similiar experiences)
Could someone else confirm that they also experience the increasing or have had similiar problems and managed to resolve it?Anecdotally, yes. Don't have exact steps for replication or precise numbers, but I have noticed this in passing. On the junk that my client considers a PC suitable for web development the typical IE7 memory footprint with the APEX 3.0 builder and several other tabs running is about 52MB. Add APEX 4.1.1 and it climbs constantly until I have to pull the plug when it gets north of 150MB as the PC can't take it.
As well that I also have Firefox and 4.1.1 is still experimental at that site...
At the moment I don't have to resolve it and if I did the only option I'd propose is the replacement of IE7.
VC wrote:
Look at this http://www.bbc.co.uk/news/technology-18440979
Alistair Laing wrote:lol @ VC - I dont shop online at work :-D
I saw that eariler this week. I do agree with the concept though.So take appropriate action: charge extra for IE7 support.
The amount of work and effort involved in making our website look normal on IE7 equalled the combined time of designing for Chrome, Safari and Firefox.Is entirely accurate. If it's stated as a requirement, itemise it as an extra on the quote.
Educate management and bean counters: show them the one line of standards-compliant CSS that's all that is necessary in Safari, Chrome, Firefox and Opera (and just possibly in IE8/9/10), how it isn't supported in IE7, and the tortuous hacks and workarounds that are required to get something equivalent working there. -
Memory Leak with cloneModelFromCastMember()?
Hello Experts!
I have been experiencing an apparent memory leak within
Director 11 when
using cloneModelFromCastMember().
I was making the assumption that calling resetWorld() on a
w3D member
onBeginSprite() would garbage collect any models previously
cloned into that
when I previously ran the movie.
However, if I repeatedly start and stop the movie Director
Gobbles roughly
10Mb more memory each time. The memory usage does not reduce
upon calling
resetWorld()
A good way to replicate this is to use
cloneModelFromCastMember() on a
largeish model in a repeat with i = 1 to 50 loop on the on
beginSprite
handler.
Start and stop the movie over and over to see Director's
memory usage hike
up.
Anybody have any advice why this is happening? Do I need to
explicitly
delete all models cloned into a member on stopMovie????
Cheers
Richard SmithHi Zzzorro,
Thanks for the advice!
Why does cloning from external w3D members help? Does it
avoid the memory
leak? It never used to happen on Director 8.5 so it has to be
a new Version
10 / 11 bug right?
I need to import several weightmapped boned characters into a
3D member, and
due to export issues each character has to have it's own w3D
file.
So I have to perform cloning at runtime to build the world. I
also need to
clone these characters based on the level, so I can't use
just one single 3D
member for both these reasons.
Thanks for any further ideas.
Richard Smith
"zzzorro" <[email protected]> wrote in
message
news:gd4sn2$2l8$[email protected]..
> as a rule of thumb:
> whenever possible avoid cloneModelFromCastMember in the
first place.
> It is highly unrecommended and the intel engineers
always recommended to
> use
> loadFile() with an external w3d file, which is much
better than having the
> w3d
> file in the castlib and using cmfcm.
> each cmfm rebuilds the whole scene and takes a lot of
time the bigger the
> scene is.
> apart from glitches like leaks, which you found right
now and other
> things.
>
> I work very much with sw3d and I barely have more than
one shockwave3d
> member
> in any of my movies. in very rare cases I use 2 sw3d
members. Other than
> that I
> use one member where I build and load everything into
from external w3d
> files
> with loadFile(), which is much more appropriate. the
only downside is that
> I
> can't change the model name, but there are ways to deal
with it.
> -
Memory Leak with GotoAndStop()
I am trying to track down a solution to a memory leak within an embedded video. If I embed a video on the timeline and then run gotoAndStop or gotoAndPlay to a specific frame every time the frame changes it takes in more memory until it crashes at about 1.7GB however if I run a straight play() on the same clip the memory usage remains constant. I have also tried System.gc() as it is an AIR App and have tried unloadAndStop() with the embeded video being loaded into a Loader and neither can reclaim any memory.
I am looking for a a way to resolve the memory leak or another way to be able to rapidly jump to specific frames of video as far as I know this is not possible with external flvs.
Thanks
Davevideo is much like a .gif file. if you start at frame 0 and jump to frame 30 it needs to redraw what it does nt have in frame 30 which means tellign it to start at frame 30 is the same as telling it to get all information from when it last changed which might be frame 27 to complete the frame of what should display on frame 30.
this is why its slow to play backwards. and best to play an flv forward.
what i would suggest if you do not need video persay, would be to use png sequences. but if your videos are long then i suppose it would be a greater advantage to keep it compressed.
what is the quality as well of the video and its size and your frame rate?
You mention that you are creating a 3d view, how is that? do you use more than 1 swf ?
I still think this does not sound like a play head issue, since the video is already compiled. -
Memory Leak with the new PatchMix App Beta?
E6300/ASUS P5B-D/2GB RAM/EMU 0404/Vista Ultimate 32bit
The problem happens after I upgrade to the PatchMix driver set dated 9/11.
The physical memory usage bumps from ~24M to 150M after running 24 hours, and I didnt load any FX.
The commit size(real memory usage) is over 500M!
This doesnt happen with the old beta driver.
Anyone has the same problem?Emon wrote:
jreid wrote:
Dare I suggest the problem might be Vista?
Yes? How exactly would Vista cause a memory leak within PatchMix DSP's GUI?
Well, just a thought. The OS is ultimately responsible for all memory management, and also the low-level graphics functions that would be called by e.g. the GUI code. I just noticed that people on XP didn't seem to be having the same problems with this beta. -
JRC and JSP memory leak...
Hi, I have an web application with Crystal Reports integrated via the JRC. However, I have a memory leak within the application. I have narrowed it down to the JSP which uses JRC code. The NetBeans profiler shows a memory leak, it appears to be a leak with the JRC code with the class (com.crystaldecisions.reports.exporters.format.page.pdf.pdflif.f). I have try changing the <timeout> tag in CRConfig and using .dispose() and .close(), all to no avail. This error may jepordize our latest production release... Please, help...
Best to download 2.0 and install all patches and test again. If not resolved then post your issue with details and code samples.
-
Media Encoder is a memory leak - windows
Applies to: Version 5.5.1.12 - 64 bit, Windows (Most likely earlier versions too)
Reproducing the problem:
Start Media Encoder as a standalone application by double clicking the icon.
Close the window (by clicking the 'x' in the top-right corner) of Media Encoder.
It does just that: closes the window. It does not close the process.
The process now has no window-handle, thus the user can not access it.
When user starts the application again, another process is created.
Thus the previous process becomes a memory leak.
Workaround:
Open Windows Task Manager by pressing Ctrl-Alt-Del keys simultaniously then selecting Task Manager
Click the 'Processes' tab
Highlight 'Adobe Media Encoder.exe'
Click 'End Process'
Ignore the warning and kill the processBill, Sometimes it takes AME and related components up to 30 seconds to close various processes. If you close the app and immediately start a new instance, the old process sees that AME is still running and may not shut down it's process until you shut down your computer. So give it a little time after shutdown to see if that helps. That said, there are situations that I have seen myself that AME would not close all processes in background. In many of those cases, it had to do with dynamic link and what type of files or assets you opend up and what application launches AME. Sometimes when AME is launched by other applications like Premiere Pro, it leaves a process alive in case PPro is using it. but if you close all Adobe apps, it should close your process as well. Over the past few cycles, we have worked on improving processes. Let me know if the above info doesn't help.
-
Memory-leak playing rtsp:// media
Hi all,
We're finding that QT has a memory leak when playing rtsp:// media - it eventually causes an out-of-memory condition in our product (we're using QT embedded in a webpage, but see the exact same thing happening in FF/3.0.10, FF/2.0.0.20, IE/7.0.5730.11 & QuickTime Player) .
We've tested with QT 7.62, 7.16 & 6.52 (all on WinXP Pro SP3) and they all have the same/similar leak. Playing this any example link (rtsp://video3.multicasttech.com/AFTVAdventure3GPP296.sdp) in QuickTime Player and monitoring it's memory usage (we used Sysinternals ProcessExplorer: http://download.sysinternals.com/Files/ProcessExplorer.zip) highlights the problem. Playing a similar file locally shows no leak.
Please let me know if you need any more info...
ChrisBCan you produce this webpage?
No, it's part of an unreleased proprietary product, so I can't post the URL. If really necessary, I could pull the <embed> tag (actually generated with the standard Apple's "QT_WriteOBJECT" JS call) out and put it on a webpage on its own, but surely we can find one...
I don't see and indication of a memory leak with QT based on using XP pro.
Really? The three systems I tested on all had the same leak. We only see this leak with rstp:// URLs. Local playback does NOT induce this leak.
The link you posted seems to be a direct download to some program
It's a link to the program we used to monitor the web browser or QuickTime Player's memory usage over time. Please re-read my post:
Playing this any example link (rtsp://video3.multicasttech.com
/AFTVAdventure3GPP296.sdp) in QuickTime Player and monitoring
it's memory usage (we used Sysinternals ProcessExplorer:
http://download.sysinternals.com/Files/ProcessExplorer.zip)
highlights the problem. Playing a similar file locally shows
no leak.
Cheers,
ChrisB -
How to fix huge iTunes memory leak in 64-bit Windows 7?
iTunes likes to allocate as much as 1.6GB of memory on my dual-quad XEON 8GB 64-Bit Windows computer and then becomes unresponsive.
This can happen several times a day and has been going on for as long as I can remember. No other software that I use does this - only Apple's iTunes. Each version I have installed of iTunes appears to have this same memory leak. Currently I am running version 10.7.0.21.
I love iTunes when it works. But having to constantly kill and relaunch the app throughout the day is bringing me down.
Searching for a fix for this on the internet just surfaces more and more complaints about this problem - but without a solution.
Having written shrinkwrapped software for end users as well as for large corporations and governments for more than 25 years I know a thing or two about software. A leak like this should take no more than a day or two to locate using modern software tools and double that to fix it. So why with each new version of iTunes does this problem persist? iTunes for Windows is the flagship software product Apple makes for non-Mac users - yet they continue to pass up each opportunity they have had over the years with each new release to fix this issue. Why is this?
Either the software engineers are not that good or they have been told NOT to spend time on this issue. I personally believe that the engineers at Apple are very good, and therefore am left thinking that the latter is more likely the case. Maybe this is to coax people to purchase a Mac so that they can finally run iTunes without these egregious memory leaks. I would like to offer another issue to consider.
Just as Amazon sold Kindles and Google sold Nexus tablets at low cost - not counting on margin for profit - but instead they wanted to saturate the marketplace with tools for making future purchases of content almost trivial to do with their devices. Apple also counts on this model with their pricer hardware - but they also have iTunes. Instead of trying to get people to switch to a MAC by continuing to avoid fixing this glaring issue in iTunes for Windows I would like to suggest that by allowing their engineers to address this issue that Apple will help keep Windows users from jumping ship to another music app. The profit to be made by keeping those Windows users happy and wedded to the iTunes store is obvious.
By continuing to keep this leak in iTunes for Windows all it does is lower my esteem for the company and start to make me wonder if the software is just as buggy on Macs.I have same issue. Ongoing for more than 1 year and currently running iTunes 11.3.
My PC is Dell OptiPlex 990 I7 processor, 8GB ram, W7 64 [always keep things patched up to latest OS updates etc]
I use this iTunes install to stream music videos etc to multiple appleTVs, ipads, iphones etc .. via Home Sharing
Store all my media including music, videos and apps on separate NAS .. so the iTunes running on PC is only doing the traffic cop role and streaming / using files stored on NAS .. creates lots of IO across my network
Previous troubleshooting suggest possible contributing causes include
a) podcast updates .. until recently I had this auto updates on multiple podcast subscriptions, presumably the iTunes would flow this from the PC to save on the NAS across the network .. if the memory leak is in the iTunes network communication layer (?bonjour?) this may be sensitive to IO that would not normally occur if the iTunes file saving was local on the same PC
b) app updates .. have 200+ apps in my library and there is always a batch of updates .. some updates 100s of MB is size .. routinely see 500MB to 1GB of updates in single update run .. all my apps are
c) streaming music / movies .. seems when we ramp up streamlining of music or movies . memory leak grows faster .. ie within hours of clean start
c) large syncs of music or videos to ipads or iphones .. noticed that get big problems when I rebuild an ipad .. I typically have 60+ GB of data in terms of apps / music / videos to load .. have to do rebuild in phases due to periodic lockups -
Custom MediaStreamSource and Memory Leaks During SampleRequested
Greetings,
I have a nasty memory leak problem that is causing me to pull my hair out.
I'm implementing a custom MediaStreamSource along with MediaTranscoder to generate video to disk. The frame generation operation occurs in the SampleRequested handler (as in the MediaStreamSource example). No matter what I do - and I've tried a
ton of options - inevitably the app runs out of memory after a couple hundred frames of HD video. Investigating, I see that indeed GC.GetTotalMemory reports an increasing, and never decreasing, amount of allocated RAM.
The frame generator in my actual app is using RenderTargetBitmap to get screen captures, and is handing the buffer to MediaStreamSample.CreateFromBuffer(). However, as you can see in the example below, the issue occurs even with a dumb allocation
of RAM and no other actual logic. Here's the code:
void _mss_SampleRequested(Windows.Media.Core.MediaStreamSource sender, MediaStreamSourceSampleRequestedEventArgs args)
if ( args.Request.StreamDescriptor is VideoStreamDescriptor )
if (_FrameCount >= 3000) return;
var videoDeferral = args.Request.GetDeferral();
var descriptor = (VideoStreamDescriptor)args.Request.StreamDescriptor;
uint frameWidth = descriptor.EncodingProperties.Width;
uint frameHeight = descriptor.EncodingProperties.Height;
uint size = frameWidth * frameHeight * 4;
byte[] buffer = null;
try
buffer = new byte[size];
// do something to create the frame
catch
App.LogAction("Ran out of memory", this);
return;
args.Request.Sample = MediaStreamSample.CreateFromBuffer(buffer.AsBuffer(), TimeFromFrame(_FrameCount++, _frameSource.Framerate));
args.Request.Sample.Duration = TimeFromFrame(1, _frameSource.Framerate);
buffer = null; // attempt to release the memory
videoDeferral.Complete();
App.LogAction("Completed Video frame " + (_FrameCount-1).ToString() + "\n" +
"Allocated memory: " + GC.GetTotalMemory(true), this);
return;
It usually fails around frame 357, with GC.GetTotalMemory() reporting 750MB allocated.
I've tried tons of work-arounds, none of which made a difference. I tried putting the code that allocates the bytes in a separate thread - no dice. I tried Task.Delay to give the GC a chance to work, on the assumption that it just had no time
to do its job. No luck.
As another experiment, I wanted to see if the problem went away if I allocated memory each frame, but never assigned it to the MediaStreamSample, instead giving the sample (constant) dummy data. Indeed, in that scenario, memory consumption stayed
constant. However, while I never get an out-of-memory exception, RequestSample just stops getting called around frame 1600 and as a result the transcode operation never actually returns to completion.
I also tried taking a cue from the SDK sample which uses C++ entirely to generate the frame. So I passed the buffer as a Platform::Array<BYTE> to a static Runtime extension class function I wrote in C++.
I won't bore you with the C++ code, but even directly copying the bytes of the array to the media sample using memcpy still had the same result! It seems that there is no way to communicate the contents of the byte[] array to the media sample without
it never being released.
I know what some will say: the difference between my code and the SDK sample, of course, is that the SDK sample generates the frame _entirely_ in C++, thus taking care of its own memory allocation and deallocation. Because I want to get
the data from RenderTargetBitmap, this isn't an option for me. (As a side note, if anyone knows if there's a way to get the contents of an RT Window using DirectX, that might work too, but I know this is not a C++ forum, so...). But more importantly,
MediaStreamSource and MediaStreamSample are managed classes that appear to allow you to generate custom frames using C# or other managed code. The MediaStreamSample.CreateFromBuffer function appears to be tailored for exactly what I want. But there appears
to be no way to release the buffer when giving the bytes to the MediaStreamSample. At least none that I can find.
I know the RT version of these classes are new to Windows 8.1, but I did see other posts going back 3 years discussing a similar issue in Silverlight. That never appears to have been resolved.
I guess the question boils down to this: how do I safely get managed data, allocated during the SampleRequested handler, to the MediaStreamSample without causing a memory leak? Also, why would the SampleRequested handler just stop getting called
out of the blue, even when I artificially eliminate the memory leak problem?
Thanks so much for all input!Hi Rob -
Thanks for your quick reply and for clarifying the terminology.
In the Memory Usage test under Analyze/Performance and Diagnostics (is that what you mean?) it's clear that each frame of video being created is not released from memory except when memory consumption gets very high. GC will occasionally kick in, but eventually
it succumbs.
Interestingly, if I reduce the frame size substantially, say 320x240, it never runs out of RAM no matter how many frames I throw at it. The Memory Usage test, however, shows the same pattern. But this time the GC can keep up and release the RAM.
After playing with this ad nauseum, I am fairly convinced I know what the problem is, but the solution still escapes me. It appears that the Transcoder is requesting frames from the MediaStreamSource (and the MediaStreamSource is providing them via
my SampleRequested handler) faster than the Transcoder can write them to disk and release them. Why would this be happening? The MediaStreamSource.BufferTime property is - I thought - used to prevent this very problem. However, changing the BufferTime seems
to have no effect at all - even changing it to ZERO doesn't change anything. If I'm right, this would explain why the GC can't do its job - it can't release the buffers I'm giving to the Transcoder via SampleRequested because the Transcoder won't give them
up until it's finished transcoding and writing them to disk. And yet the transcoder keeps requesting samples until there's no more memory to create them with.
The following code, which I made from scratch to illustrate my scenario, should be air-tight according to everything I've read. And yet, it still runs out of memory when the frame size is too large.
If you or anyone else can spot the problem in this code, I'd be thrilled to hear it. Maybe I'm omitting a key step with regard to getting the deferral? Or maybe it's a bug in the back-end? Can I "slow down" the transcoder and force it to release samples
it's already used?
Anyway here's the new code, which other than App.cs is everything. So if I'm doing something wrong it will be in this module:
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Diagnostics;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Popups;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.Media.MediaProperties;
using Windows.Media.Core;
using Windows.Media.Transcoding;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace MyTranscodeTest
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
MediaTranscoder _transcoder;
MediaStreamSource _mss;
VideoStreamDescriptor _videoSourceDescriptor;
const int c_width = 1920;
const int c_height = 1080;
const int c_frames = 10000;
const int c_frNumerator = 30000;
const int c_frDenominator = 1001;
uint _frameSizeBytes;
uint _frameDurationTicks;
uint _transcodePositionTicks = 0;
uint _frameCurrent = 0;
Random _random = new Random();
public MainPage()
this.InitializeComponent();
private async void GoButtonClicked(object sender, RoutedEventArgs e)
Windows.Storage.Pickers.FileSavePicker picker = new Windows.Storage.Pickers.FileSavePicker();
picker.FileTypeChoices.Add("MP4 File", new List<string>() { ".MP4" });
Windows.Storage.StorageFile file = await picker.PickSaveFileAsync();
if (file == null) return;
Stream outputStream = await file.OpenStreamForWriteAsync();
var transcodeTask = (await this.InitializeTranscoderAsync(outputStream)).TranscodeAsync();
transcodeTask.Progress = (asyncInfo, progressInfo) =>
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
_ProgressReport.Text = "Sourcing frame " + _frameCurrent.ToString() + " of " + c_frames.ToString() +
" with " + GC.GetTotalMemory(false).ToString() + " bytes allocated.";
await transcodeTask;
MessageDialog dialog = new MessageDialog("Transcode completed.");
await dialog.ShowAsync();
async Task<PrepareTranscodeResult> InitializeTranscoderAsync (Stream output)
_transcoder = new MediaTranscoder();
_transcoder.HardwareAccelerationEnabled = false;
_videoSourceDescriptor = new VideoStreamDescriptor(VideoEncodingProperties.CreateUncompressed( MediaEncodingSubtypes.Bgra8, c_width, c_height ));
_videoSourceDescriptor.EncodingProperties.PixelAspectRatio.Numerator = 1;
_videoSourceDescriptor.EncodingProperties.PixelAspectRatio.Denominator = 1;
_videoSourceDescriptor.EncodingProperties.FrameRate.Numerator = c_frNumerator;
_videoSourceDescriptor.EncodingProperties.FrameRate.Denominator = c_frDenominator;
_videoSourceDescriptor.EncodingProperties.Bitrate = (uint)((c_width * c_height * 4 * 8 * (ulong)c_frDenominator) / (ulong)c_frNumerator);
_frameDurationTicks = (uint)(10000000 * (ulong)c_frDenominator / (ulong)c_frNumerator);
_frameSizeBytes = c_width * c_height * 4;
_mss = new MediaStreamSource(_videoSourceDescriptor);
_mss.BufferTime = TimeSpan.FromTicks(_frameDurationTicks);
_mss.Duration = TimeSpan.FromTicks( _frameDurationTicks * c_frames );
_mss.Starting += _mss_Starting;
_mss.Paused += _mss_Paused;
_mss.SampleRequested += _mss_SampleRequested;
MediaEncodingProfile outputProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Ntsc);
outputProfile.Audio = null;
return await _transcoder.PrepareMediaStreamSourceTranscodeAsync(_mss, output.AsRandomAccessStream(), outputProfile);
void _mss_Paused(MediaStreamSource sender, object args)
throw new NotImplementedException();
void _mss_Starting(MediaStreamSource sender, MediaStreamSourceStartingEventArgs args)
args.Request.SetActualStartPosition(new TimeSpan(0));
/// <summary>
/// This is derived from the sample in "Windows 8.1 Apps with Xaml and C# Unleashed"
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
void _mss_SampleRequested(MediaStreamSource sender, MediaStreamSourceSampleRequestedEventArgs args)
if (_frameCurrent == c_frames) return;
var deferral = args.Request.GetDeferral();
byte[] frameBuffer;
try
frameBuffer = new byte[_frameSizeBytes];
this._random.NextBytes(frameBuffer);
catch
throw new Exception("Sample source ran out of RAM");
args.Request.Sample = MediaStreamSample.CreateFromBuffer(frameBuffer.AsBuffer(), TimeSpan.FromTicks(_transcodePositionTicks));
args.Request.Sample.Duration = TimeSpan.FromTicks(_frameDurationTicks);
args.Request.Sample.KeyFrame = true;
_transcodePositionTicks += _frameDurationTicks;
_frameCurrent++;
deferral.Complete();
Again, I can't see any reason why this shouldn't work. You'll note it mirrors pretty closely the sample in the Windows 8.1 Apps With Xaml Unleashed book (Chapter 14). The difference is I'm feeding the samples to a transcoder rather than a MediaElement (which,
again should be no issue).
Thanks again for any suggestions!
Peter -
How to deal with Memory Leaks, that are caused by Binding
Hi, I recently noticed (huge?) memory leaks in my application and suspect bindings to be the cause of all the evil.
I made a little test case, which confirms my suspicion:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestAppMemoryLeak extends Application {
public static void main(String[] args) {
launch(args);
@Override
public void start(Stage stage) throws Exception {
VBox root = new VBox();
Button button = null;
for (int i = 0; i < 100000; i++) {
button = new Button();
button.textProperty().bind(text);
button.textProperty().unbind(); // if you don't call this, you can notice the increased memory of the java process.
root.getChildren().add(button);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
private StringProperty text = new SimpleStringProperty("test");
}Now the problem is, HOW can I know, when a variable is no longer needed or overwritten by a new instance.
Just an example:
I have a ListView with a Cell Factory. In the updateItem method, I add a ContextMenu. The textProperty of each MenuItem is bound to a kind of global property, like in the example above. I have to do it in the updateItem method, since the ContextMenu differs depending on the item.
So every time the updateItem method is called a new ContextMenu is created, which binds some properties, but the old context menus remain in memory.
I guess there could be many more example.
How can I deal with it?I've dealt with this situation and created a Jira issue for it, but I also have a work-around that is a bit unwieldy but works. I'll share it with you.
The bug that deals with this (in part atleast): http://javafx-jira.kenai.com/browse/RT-20616
The solution is to use weak invalidation listeners, however they are a bit of a pain to use as you cannot do it with something simplistic as "bindWeakly"... and you need to keep a reference around to the wrapped listener otherwise it will just get garbage collected immediately (as it is only weakly referenced). Some very odd bugs can surface if weak listeners disappear randomly because you forgot to reference them :)
Anyway, see this code below, it shows you some code that is called from a TreeCell's updateItem method (I've wrapped it in some more layers in my program, but it is essentially the same as an updateItem method):
public class EpisodeCell extends DuoLineCell implements MediaNodeCell {
private final WeakBinder binder = new WeakBinder();
@Override
public void configureCell(MediaNode mediaNode) {
MediaItem item = mediaNode.getMediaItem();
StringBinding episodeRange = MapBindings.selectString(mediaNode.dataMapProperty(), Episode.class, "episodeRange");
binder.unbindAll();
binder.bind(titleProperty(), MapBindings.selectString(mediaNode.dataMapProperty(), Media.class, "title"));
binder.bind(ratingProperty(), MapBindings.selectDouble(mediaNode.dataMapProperty(), Media.class, "rating").divide(10));
binder.bind(extraInfoProperty(), Bindings.when(episodeRange.isNull()).then(new SimpleStringProperty("Special")).otherwise(episodeRange));
binder.bind(viewedProperty(), item.viewedProperty());
subtitleProperty().set("");
}This code makes use of a class called WeakBinder -- it is a helper class that can make Weak bindings and can keep track of them. When you call unbindAll() on it, all of the bindings it created before are released immediately (although they will also disappear when the Cell itself is garbage collected, which is possible because it only makes weak references).
I've tested this extensively and it solves the problem of Cells keeping references to objects with much longer life cycles (in my case, the MediaNode passed in has a longer lifecycle than the cells and so it is important to bind weakly to it). Before this would create huge memory leaks (crashing my program within a minute if you kept refreshing the Tree)... now it survives hours atleast and the Heap usage stays in a fixed range which means it is correctly able to collect all garbage).
The code for WeakBinder is below (you can consider it public domain, so use it as you see fit, or write your own):
package hs.mediasystem.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.WeakInvalidationListener;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
public class WeakBinder {
private final List<Object> hardRefs = new ArrayList<>();
private final Map<ObservableValue<?>, WeakInvalidationListener> listeners = new HashMap<>();
public void unbindAll() {
for(ObservableValue<?> observableValue : listeners.keySet()) {
observableValue.removeListener(listeners.get(observableValue));
hardRefs.clear();
listeners.clear();
public <T> void bind(final Property<T> property, final ObservableValue<? extends T> dest) {
InvalidationListener invalidationListener = new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
property.setValue(dest.getValue());
WeakInvalidationListener weakInvalidationListener = new WeakInvalidationListener(invalidationListener);
listeners.put(dest, weakInvalidationListener);
dest.addListener(weakInvalidationListener);
property.setValue(dest.getValue());
hardRefs.add(dest);
hardRefs.add(invalidationListener);
}Let me know if this solves your problem. -
How can I address a memory leak problem with Firefox?
I have happily used Firefox for the past 7 years, and have rarely had difficulties. However, I am having some trouble now; Firefox (running 3.6.6) seems to have a memory leak on my machine. It's slower than what was discussed in other forum posts, but it still scales up slowly to multiple hundred MBs of Memory with very little CPU usage.
I have tried disabling add-ons and extensions, but this does not stop the problem. I have cleared my cache and other stored data, but that also does not help. Has anyone experienced a similar problem that might be able to help?
== This happened ==
Every time Firefox opened
== within last two weeksHi reble0708,
I have Java console disabled on my Firefox browser.Everything is working fine for me. There maybe other problem on your browser which is making PDF document faded and blurry. Can you post the link where you found the problem viewing the PDF document?
Btw, you can go to ftp://ftp.mozilla.org/pub/firefox/releases/ and select the previous version of Firefox from the given options. There's no need to uninstall Firefox before you downgrade to the previous version of it.But before new installation, backup your Firefox profile folder.
edit: replaced random unofficial download site link. -
Pro*c multithreaded application has memory leak
Hi there,
I posted this message a week ago in OCI section, nobody answer me.
I am really curious if my application has a bug or the pro*c has a bug.
Anyone can compile the sample code and test it easily.
I made multithreaded application which queries dynamic SQL, it works.
But the memory leaks when i query the SQL statement.
The more memory leaks, the more i query the SQL statement, even same SQL
statement.
I check it with top, shell command.
My machine is SUN E450, Solaris 8. Oracle 9.2.0.1
Compiler : gcc (GCC) 3.2.2
I changed source code which is from
$(ORACLE_HOME)/precomp/demo/proc/sample10.pc
the sample10 doesn't need to be multithreaded. But i think it has to work
correctly if i changed it to multithreaded application.
the make file and source code will be placed below.
I have to figure out the problem.
Please help
Thanks in advance,
the make file is below
HOME = /user/jkku
ORA = $(ORACLE_HOME)
CC = gcc
PROC = proc
LC_INCL = -I$(HOME)/work/dbmss/libs/include
lc_incl = include=$(HOME)/work/dbmss/libs/include
SYS_INCL =
sys_incl =
ORA_INCL = -I. \
-I$(ORA)/precomp/public \
-I$(ORA)/rdbms/public \
-I$(ORA)/rdbms/demo \
-I$(ORA)/rdbms/pbsql/public \
-I$(ORA)/network/public \
-DSLMXMX_ENABLE -DSLTS_ENABLE -D_SVID_GETTOD
INCLUDES = $(LC_INCL) $(SYS_INCL) $(ORA_INCL)
includes = $(lc_incl) $(sys_incl)
LC_LIBS =
SYS_LIBS = -lpthread -lsocket -lnsl -lrt
ORA_LIBS = -L$(ORA)/lib/ -lclntsh
LIBS = $(LC_LIBS) $(SYS_LIBS) $(ORA_LIBS)
# Define C Compiler flags
CFLAGS += -D_Solaris64_ -m64
CFLAGS += -g -D_REENTRANT
# Define pro*c Compiler flags
PROCFLAGS += THREADS=YES
PROCFLAGS += CPOOL=YES
# Our object files
PRECOMPS = sample10.c
OBJS = sample10.o
.SUFFIXES: .o .c .pc
.c.o:
$(CC) -c $(CFLAGS) $(INCLUDES) $*.c
.pc.c:
$(PROC) $(PROCFLAGS) $(includes) $*.pc $*.c
all: sample10
sample10: $(PRECOMPS) $(OBJS)
$(CC) $(CFLAGS) -o sample10 $(OBJS) $(LIBS)
clean:
rm -rf *.o sample10 sample10.c
the source code is below which i changed the oracle sample10.pc to
multithreaded application.
Sample Program 10: Dynamic SQL Method 4
This program connects you to ORACLE using your username and
password, then prompts you for a SQL statement. You can enter
any legal SQL statement. Use regular SQL syntax, not embedded SQL.
Your statement will be processed. If it is a query, the rows
fetched are displayed.
You can enter multi-line statements. The limit is 1023 characters.
This sample program only processes up to MAX_ITEMS bind variables and
MAX_ITEMS select-list items. MAX_ITEMS is #defined to be 40.
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include <sqlda.h>
#include <stdlib.h>
#include <sqlcpr.h>
/* Maximum number of select-list items or bind variables. */
#define MAX_ITEMS 40
/* Maximum lengths of the names of the
select-list items or indicator variables. */
#define MAX_VNAME_LEN 30
#define MAX_INAME_LEN 30
#ifndef NULL
#define NULL 0
#endif
/* Prototypes */
#if defined(__STDC__)
void sql_error(void);
int oracle_connect(void);
int alloc_descriptors(int, int, int);
int get_dyn_statement(void);
void set_bind_variables(void);
void process_select_list(void);
void help(void);
#else
void sql_error(/*_ void _*/);
int oracle_connect(/*_ void _*/);
int alloc_descriptors(/*_ int, int, int _*/);
int get_dyn_statement(/* void _*/);
void set_bind_variables(/*_ void -*/);
void process_select_list(/*_ void _*/);
void help(/*_ void _*/);
#endif
char *dml_commands[] = {"SELECT", "select", "INSERT", "insert",
"UPDATE", "update", "DELETE", "delete"};
EXEC SQL INCLUDE sqlda;
EXEC SQL INCLUDE sqlca;
EXEC SQL BEGIN DECLARE SECTION;
char dyn_statement[1024];
EXEC SQL VAR dyn_statement IS STRING(1024);
EXEC SQL END DECLARE SECTION;
EXEC ORACLE OPTION (ORACA=YES);
EXEC ORACLE OPTION (RELEASE_CURSOR=YES);
SQLDA *bind_dp;
SQLDA *select_dp;
/* Define a buffer to hold longjmp state info. */
jmp_buf jmp_continue;
char *db_uid="dbmuser/dbmuser@dbmdb";
sql_context ctx;
int err_sql;
enum{
SQL_SUCC=0,
SQL_ERR,
SQL_NOTFOUND,
SQL_UNIQUE,
SQL_DISCONNECT,
SQL_NOTNULL
int main()
int i;
EXEC SQL ENABLE THREADS;
EXEC SQL WHENEVER SQLERROR DO sql_error();
EXEC SQL WHENEVER NOT FOUND DO sql_not_found();
/* Connect to the database. */
if (connect_database() < 0)
exit(1);
EXEC SQL CONTEXT USE :ctx;
/* Process SQL statements. */
for (;;)
/* Allocate memory for the select and bind descriptors. */
if (alloc_descriptors(MAX_ITEMS, MAX_VNAME_LEN, NAME_LEN) != 0)
exit(1);
(void) setjmp(jmp_continue);
/* Get the statement. Break on "exit". */
if (get_dyn_statement() != 0)
break;
EXEC SQL PREPARE S FROM :dyn_statement;
EXEC SQL DECLARE C CURSOR FOR S;
/* Set the bind variables for any placeholders in the
SQL statement. */
set_bind_variables();
/* Open the cursor and execute the statement.
* If the statement is not a query (SELECT), the
* statement processing is completed after the
* OPEN.
EXEC SQL OPEN C USING DESCRIPTOR bind_dp;
/* Call the function that processes the select-list.
* If the statement is not a query, this function
* just returns, doing nothing.
process_select_list();
/* Tell user how many rows processed. */
for (i = 0; i < 8; i++)
if (strncmp(dyn_statement, dml_commands, 6) == 0)
printf("\n\n%d row%c processed.\n", sqlca.sqlerrd[2], sqlca.sqlerrd[2] == 1 ? '\0' : 's');
break;
/* Close the cursor. */
EXEC SQL CLOSE C;
/* When done, free the memory allocated for pointers in the bind and
select descriptors. */
for (i = 0; i < MAX_ITEMS; i++)
if (bind_dp->V != (char *) 0)
free(bind_dp->V);
free(bind_dp->I); /* MAX_ITEMS were allocated. */
if (select_dp->V != (char *) 0)
free(select_dp->V);
free(select_dp->I); /* MAX_ITEMS were allocated. */
/* Free space used by the descriptors themselves. */
SQLSQLDAFree(ctx, bind_dp);
SQLSQLDAFree(ctx, select_dp);
} /* end of for(;;) statement-processing loop */
disconnect_database();
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL COMMIT WORK RELEASE;
puts("\nHave a good day!\n");
return;
* Allocate the BIND and SELECT descriptors using sqlald().
* Also allocate the pointers to indicator variables
* in each descriptor. The pointers to the actual bind
* variables and the select-list items are realloc'ed in
* the set_bind_variables() or process_select_list()
* routines. This routine allocates 1 byte for select_dp->V
* and bind_dp->V, so the realloc will work correctly.
alloc_descriptors(size, max_vname_len, max_iname_len)
int size;
int max_vname_len;
int max_iname_len;
int i;
* The first sqlald parameter determines the maximum number of
* array elements in each variable in the descriptor. In
* other words, it determines the maximum number of bind
* variables or select-list items in the SQL statement.
* The second parameter determines the maximum length of
* strings used to hold the names of select-list items
* or placeholders. The maximum length of column
* names in ORACLE is 30, but you can allocate more or less
* as needed.
* The third parameter determines the maximum length of
* strings used to hold the names of any indicator
* variables. To follow ORACLE standards, the maximum
* length of these should be 30. But, you can allocate
* more or less as needed.
if ((bind_dp =
SQLSQLDAAlloc(ctx, size, max_vname_len, max_iname_len)) ==
(SQLDA *) 0)
fprintf(stderr,
"Cannot allocate memory for bind descriptor.");
return -1; /* Have to exit in this case. */
if ((select_dp =
SQLSQLDAAlloc(ctx, size, max_vname_len, max_iname_len)) == (SQLDA *)
0)
fprintf(stderr,
"Cannot allocate memory for select descriptor.");
return -1;
select_dp->N = MAX_ITEMS;
/* Allocate the pointers to the indicator variables, and the
actual data. */
for (i = 0; i < MAX_ITEMS; i++) {
bind_dp->I = (short *) malloc(sizeof (short));
select_dp->I = (short *) malloc(sizeof(short));
bind_dp->V = (char *) malloc(1);
select_dp->V = (char *) malloc(1);
return 0;
int get_dyn_statement()
char *cp, linebuf[256];
int iter, plsql;
for (plsql = 0, iter = 1; ;)
if (iter == 1)
printf("\nSQL> ");
dyn_statement[0] = '\0';
fgets(linebuf, sizeof linebuf, stdin);
cp = strrchr(linebuf, '\n');
if (cp && cp != linebuf)
*cp = ' ';
else if (cp == linebuf)
continue;
if ((strncmp(linebuf, "EXIT", 4) == 0) ||
(strncmp(linebuf, "exit", 4) == 0))
return -1;
else if (linebuf[0] == '?' ||
(strncmp(linebuf, "HELP", 4) == 0) ||
(strncmp(linebuf, "help", 4) == 0))
help();
iter = 1;
continue;
if (strstr(linebuf, "BEGIN") ||
(strstr(linebuf, "begin")))
plsql = 1;
strcat(dyn_statement, linebuf);
if ((plsql && (cp = strrchr(dyn_statement, '/'))) ||
(!plsql && (cp = strrchr(dyn_statement, ';'))))
*cp = '\0';
break;
else
iter++;
printf("%3d ", iter);
return 0;
void set_bind_variables()
int i, n;
char bind_var[64];
/* Describe any bind variables (input host variables) */
EXEC SQL WHENEVER SQLERROR DO sql_error();
bind_dp->N = MAX_ITEMS; /* Initialize count of array elements. */
EXEC SQL DESCRIBE BIND VARIABLES FOR S INTO bind_dp;
/* If F is negative, there were more bind variables
than originally allocated by sqlald(). */
if (bind_dp->F < 0)
printf ("\nToo many bind variables (%d), maximum is %d\n.",
-bind_dp->F, MAX_ITEMS);
return;
/* Set the maximum number of array elements in the
descriptor to the number found. */
bind_dp->N = bind_dp->F;
/* Get the value of each bind variable as a
* character string.
* C contains the length of the bind variable
* name used in the SQL statement.
* S contains the actual name of the bind variable
* used in the SQL statement.
* L will contain the length of the data value
* entered.
* V will contain the address of the data value
* entered.
* T is always set to 1 because in this sample program
* data values for all bind variables are entered
* as character strings.
* ORACLE converts to the table value from CHAR.
* I will point to the indicator value, which is
* set to -1 when the bind variable value is "null".
for (i = 0; i < bind_dp->F; i++)
printf ("\nEnter value for bind variable %.*s: ",
(int)bind_dp->C, bind_dp->S);
fgets(bind_var, sizeof bind_var, stdin);
/* Get length and remove the new line character. */
n = strlen(bind_var) - 1;
/* Set it in the descriptor. */
bind_dp->L = n;
/* (re-)allocate the buffer for the value.
sqlald() reserves a pointer location for
V but does not allocate the full space for
the pointer. */
bind_dp->V = (char *) realloc(bind_dp->V, (bind_dp->L + 1));
/* And copy it in. */
strncpy(bind_dp->V, bind_var, n);
/* Set the indicator variable's value. */
if ((strncmp(bind_dp->V, "NULL", 4) == 0) ||
(strncmp(bind_dp->V, "null", 4) == 0))
*bind_dp->I = -1;
else
*bind_dp->I = 0;
/* Set the bind datatype to 1 for CHAR. */
bind_dp->T = 1;
return;
void process_select_list()
int i, null_ok, precision, scale;
if ((strncmp(dyn_statement, "SELECT", 6) != 0) &&
(strncmp(dyn_statement, "select", 6) != 0))
select_dp->F = 0;
return;
/* If the SQL statement is a SELECT, describe the
select-list items. The DESCRIBE function returns
their names, datatypes, lengths (including precision
and scale), and NULL/NOT NULL statuses. */
select_dp->N = MAX_ITEMS;
EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;
/* If F is negative, there were more select-list
items than originally allocated by sqlald(). */
if (select_dp->F < 0)
printf ("\nToo many select-list items (%d), maximum is %d\n",
-(select_dp->F), MAX_ITEMS);
return;
/* Set the maximum number of array elements in the
descriptor to the number found. */
select_dp->N = select_dp->F;
/* Allocate storage for each select-list item.
sqlprc() is used to extract precision and scale
from the length (select_dp->L).
sqlnul() is used to reset the high-order bit of
the datatype and to check whether the column
is NOT NULL.
CHAR datatypes have length, but zero precision and
scale. The length is defined at CREATE time.
NUMBER datatypes have precision and scale only if
defined at CREATE time. If the column
definition was just NUMBER, the precision
and scale are zero, and you must allocate
the required maximum length.
DATE datatypes return a length of 7 if the default
format is used. This should be increased to
9 to store the actual date character string.
If you use the TO_CHAR function, the maximum
length could be 75, but will probably be less
(you can see the effects of this in SQL*Plus).
ROWID datatype always returns a fixed length of 18 if
coerced to CHAR.
LONG and
LONG RAW datatypes return a length of 0 (zero),
so you need to set a maximum. In this example,
it is 240 characters.
printf ("\n");
for (i = 0; i < select_dp->F; i++)
char title[MAX_VNAME_LEN];
/* Turn off high-order bit of datatype (in this example,
it does not matter if the column is NOT NULL). */
sqlnul ((unsigned short *)&(select_dp->T), (unsigned short
*)&(select_dp->T), &null_ok);
switch (select_dp->T)
case 1 : /* CHAR datatype: no change in length
needed, except possibly for TO_CHAR
conversions (not handled here). */
break;
case 2 : /* NUMBER datatype: use sqlprc() to
extract precision and scale. */
sqlprc ((unsigned int *)&(select_dp->L), &precision,
&scale);
/* Allow for maximum size of NUMBER. */
if (precision == 0) precision = 40;
/* Also allow for decimal point and
possible sign. */
/* convert NUMBER datatype to FLOAT if scale > 0,
INT otherwise. */
if (scale > 0)
select_dp->L = sizeof(float);
else
select_dp->L = sizeof(int);
break;
case 8 : /* LONG datatype */
select_dp->L = 240;
break;
case 11 : /* ROWID datatype */
case 104 : /* Universal ROWID datatype */
select_dp->L = 18;
break;
case 12 : /* DATE datatype */
select_dp->L = 9;
break;
case 23 : /* RAW datatype */
break;
case 24 : /* LONG RAW datatype */
select_dp->L = 240;
break;
/* Allocate space for the select-list data values.
sqlald() reserves a pointer location for
V but does not allocate the full space for
the pointer. */
if (select_dp->T != 2)
select_dp->V = (char *) realloc(select_dp->V,
select_dp->L + 1);
else
select_dp->V = (char *) realloc(select_dp->V,
select_dp->L);
/* Print column headings, right-justifying number
column headings. */
/* Copy to temporary buffer in case name is null-terminated */
memset(title, ' ', MAX_VNAME_LEN);
strncpy(title, select_dp->S, select_dp->C);
if (select_dp->T == 2)
if (scale > 0)
printf ("%.*s ", select_dp->L+3, title);
else
printf ("%.*s ", select_dp->L, title);
else
printf("%-.*s ", select_dp->L, title);
/* Coerce ALL datatypes except for LONG RAW and NUMBER to
character. */
if (select_dp->T != 24 && select_dp->T != 2)
select_dp->T = 1;
/* Coerce the datatypes of NUMBERs to float or int depending on
the scale. */
if (select_dp->T == 2)
if (scale > 0)
select_dp->T = 4; /* float */
else
select_dp->T = 3; /* int */
printf ("\n\n");
/* FETCH each row selected and print the column values. */
EXEC SQL WHENEVER NOT FOUND GOTO end_select_loop;
for (;;)
EXEC SQL FETCH C USING DESCRIPTOR select_dp;
/* Since each variable returned has been coerced to a
character string, int, or float very little processing
is required here. This routine just prints out the
values on the terminal. */
for (i = 0; i < select_dp->F; i++)
if (*select_dp->I < 0)
if (select_dp->T == 4)
printf ("%-*c ",(int)select_dp->L+3, ' ');
else
printf ("%-*c ",(int)select_dp->L, ' ');
else
if (select_dp->T == 3) /* int datatype */
printf ("%*d ", (int)select_dp->L,
*(int *)select_dp->V);
else if (select_dp->T == 4) /* float datatype */
printf ("%*.2f ", (int)select_dp->L,
*(float *)select_dp->V);
else /* character string */
printf ("%-*.*s ", (int)select_dp->L,
(int)select_dp->L, select_dp->V);
printf ("\n");
end_select_loop:
return;
void help()
puts("\n\nEnter a SQL statement or a PL/SQL block at the SQL> prompt.");
puts("Statements can be continued over several lines, except");
puts("within string literals.");
puts("Terminate a SQL statement with a semicolon.");
puts("Terminate a PL/SQL block (which can contain embedded
semicolons)");
puts("with a slash (/).");
puts("Typing \"exit\" (no semicolon needed) exits the program.");
puts("You typed \"?\" or \"help\" to get this message.\n\n");
int connect_database()
err_sql = SQL_SUCC;
EXEC SQL WHENEVER SQLERROR DO sql_error();
EXEC SQL WHENEVER NOT FOUND DO sql_not_found();
EXEC SQL CONTEXT ALLOCATE :ctx;
EXEC SQL CONTEXT USE :ctx;
EXEC SQL CONNECT :db_uid;
if(err_sql != SQL_SUCC){
printf("err => connect database(ctx:%ld, uid:%s) failed!\n", ctx, db_uid);
return -1;
return 1;
int disconnect_database()
err_sql = SQL_SUCC;
EXEC SQL WHENEVER SQLERROR DO sql_error();
EXEC SQL WHENEVER NOT FOUND DO sql_not_found();
EXEC SQL CONTEXT USE :ctx;
EXEC SQL COMMIT WORK RELEASE;
EXEC SQL CONTEXT FREE:ctx;
return 1;
void sql_error()
printf("err => %.*s", sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc);
printf("in \"%.*s...\'\n", oraca.orastxt.orastxtl, oraca.orastxt.orastxtc);
printf("on line %d of %.*s.\n\n", oraca.oraslnr, oraca.orasfnm.orasfnml,
oraca.orasfnm.orasfnmc);
switch(sqlca.sqlcode) {
case -1: /* unique constraint violated */
err_sql = SQL_UNIQUE;
break;
case -1012: /* not logged on */
case -1089:
case -3133:
case -1041:
case -3114:
case -3113:
/* �6�Ŭ�� shutdown�ǰų� �α��� ���°� �ƴҶ� ��b�� �õ� */
/* immediate shutdown in progress - no operations are permitted */
/* end-of-file on communication channel */
/* internal error. hostdef extension doesn't exist */
err_sql = SQL_DISCONNECT;
break;
case -1400:
err_sql = SQL_NOTNULL;
break;
default:
err_sql = SQL_ERR;
break;
EXEC SQL CONTEXT USE :ctx;
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL ROLLBACK WORK;
void sql_not_found()
err_sql = SQL_NOTFOUND;Hi Jane,
What version of Berkeley DB XML are you using?
What is your operating system and your hardware platform?
For how long have been the application running?
What is your current container size?
What's set for EnvironmentConfig.setThreaded?
Do you know if containers have previously not been closed correctly?
Can you please post the entire error output?
What's the JDK version, 1.4 or 1.5?
Thanks,
Bogdan -
HTTPService + XML Load + Memory Leak
Hi all....
I have noticed a memory leak in my application. This leak was
not apparent when the application was completed some months back
which is what left me a little confused as all I have done since
was upgrade to Flex 3 and possibly updated / changed my Flash
player.
I think I have found the cause to this problem (below) but am
not 100% sure that it is the "actual" problem or any reasons to
back my thoughts up, so have listed what I have checked / tried
along the way (maybe I have missed something)....
My Discovery Process:
I started profiling my application but did not find anything
out of the ordinary. I did a code walk-through double checking I
had cleaned up after myself, removing and even nulling all items
etc but still to now success - the leak is still there.
I have profiled the app in the profiler for reasonably long
periods of time.
All the classes etc being used within the app are consistent
in size and instance amount and there is no sign of any apparent
leak.
I am using a HTTPService that is loading XML data which I am
refreshing every 5 seconds. On this 5 second data refresh some
class instances are incremented but are restored to the expected
amount after a GC has occurred. The GC seems to take longer, the
longer the app is running, therefore more and more instances are
being added to the app, but when the GC eventually runs it "seems"
to clear these instances to the expected amount.
After scratching my head for a while I decided to make a copy
of my application, rip everything out, and focus in my data load,
where I found a problem!
I have now just a HTTPService that loads an XML file every 5
seconds, and this is all I currently have in the app (as I ripped
the rest of the code out), e.g:
Code:
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
....... creationComplete="initApp()" >
<mx:HTTPService
id="httpServiceResults"
url="
http://myIP:myPort/myRoot/myXML.cfm"
resultFormat="e4x"
result="httpResultHandler(event)" />
<script....... >
private var timerPulse:Timer;
private function initApp():void
httpServiceResults.send();
timerPulse = new Timer(5000, 0);
private function httpResultHandler(event:ResultEvent):void
timerPulse.start();
timerPulse.addEventListener(TimerEvent.TIMER, timerRefresh);
public function timerRefresh(eventObj:TimerEvent):void
timerPulse.stop();
timerPulse.removeEventListener(TimerEvent.TIMER,
timerRefresh);
timerPulse.reset();
httpServiceResults.send();
</script>
</mx:Application>
This is pretty much the code I am currently using and it
leaks.
I ran and monitored this in both the profiler and the
activity / task manager, and after running the app for 1800 seconds
(30 min) in the profiler, the memory size grew from 50mg to 165mg
just sending the HTTPService.
I tried loading the service in multiple ways including in AS
rather than MXML creating new instances of it each time, resetting
it, nulling it etc... but nothing prevented this memory increase.
I then tried to load the XML using different methods such as
using the URLRequest and URLLoader which again caused a memory
leak.
What still confuses me is that this leak did not exist in the
previous version and not a great deal has changed since then apart
from upgrading to Flex 3 and possibly upgrading my Flash payer
(which I believe is a possible cause)
After looking into this issue a bit more deeply, I read a few
blogs / forums and other people are experiencing the same problems
- even with a lot bigger leaks in some cases all when reloading
large sets of XML data into Flex - however, I as of yet found no
solution to this leak - people with a similar problem believe it is
not due to a memory leak more a GC error, and others pointing
towards the Flash Player itself that is leaking - I don't really
know.
Findings so far during investigation of this issue:
* App leaks for both HTTPService and ULRRequest / URLLoader
methods
* App only leaks when calling a data loader
* The size of the leak seems to depend on the size of the
XML being loaded
* The size of the leak also seems to be affected by the
applications heaviness - the greater seems to enhance the leak
An interesting factor I have noticed is that if I copy the
XML from my "myXML.cfm" that I link to in my HTTPService and copy
the contents of the file into my own XML file stored within the
Flex project root itself: ""myXML.xml"" the leak disappears... like
it seems to link when loading the XML over a network, however as my
network knowledge is not great I am not sure what to make of this -
any ideas???
Could the connection to the XML document cause leaks??? is
there anything else that could cause this leak??? have I something
in my code sample that could cause this leak??? or could any of the
other things I have mentioed cause this leak???
Any help / ideas would be greatly appreciated.
Thanks,
Jon.I also observed heavy memory leak from using httpservice with
XML data. I am using Flex3 builder under Linux. My Flex application
polls httpservice every 10 seconds. The reply is a short XML
message less than 100 bytes. This simple polling will consume 30+
MB of memory every hour. I leave it idling for several hours and it
took 200 MB of memory. No sign of garbage collection at all.
Maybe you are looking for
-
HP Officejet Pro 8600 no possibility to configure Port
My OS is Win 8.1 (last release), last Printer Driver version, last Printer Install Wizard used. My first Printer "HP Officejet Pro 8600" folling down about Screen issue. I do an exchange with same model, i unsinstall and reinstall the full with wizar
-
I am trying to print a form with the following measures, height: 404, width: 639. The problem is that when printing, I need to choose the size of A4 paper, but in doing so I lose the positioning settings I had configured in the template of the form.
-
N97 Backup and missing messages - best memory loca...
Backed up my data (like a good little boy) via PC Suite last night awaiting the upgrade (currently V 10.0.012) and found all my messages and emails gone. Found the solution to this (from sidtrip) in the "blackhole" N97 bugs post. It appears the updat
-
RAF support, does it work with non-Fuji lenses like Zeiss TOUIT
Hello, I am shoorting eith a Fujifilm X-E2. The camera lists as supported in cameraraw 8.4. When I scroll through the camera-options in the development module I don't find my camera. Futher asking around (Fuji) told me that the support is "build in"
-
Loosing Time Code FC6 - Mini DV
Hi Gang Never expereinced loosing time code before. Have noticed it's becoming problematic, (during capture), when tape was stopped-started as it was being recorded. Never had this problem before. Have tried two different Panasonic Camcorders, (both