Hi guys new to .Net Gadgeteer.
I am trying to find solution for few error can any one help me?
using System;
using Microsoft.SPOT;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Microsoft.SPOT.Net.NetworkInformation;
using System.Net;
using System.Text;
using Microsoft.SPOT.Time;
using Amqp;
using Amqp.Framing;
using Gadgeteer.Modules.GHIElectronics;
namespace GadgeteerApp18
{
public partial class Program
{
GT.Timer timer;
HttpWebRequest httpReq;
const string sbNamespace = “https://neweventhub.servicebus.windows.net/”;
const string keyName = “SendRule”;
const string keyValue = “Tq9rQ4Wf3lOY0u3GaWhTn64tK4sxQKp+48NMgGTy7zc=”;
const string entity = “connectmeeventhub”;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
I am sending another code as I have divided my Above code to understand whats wrong.
Sensor are reading fine and alright even there is no error occurring.
But whenever trying to send data through Http or AMQP The error of memory pops up.
Code tags are square brackets as you kind of used in your edited first post.
So every second you post. Perhaps you should try every 10 seconds and see how that helps. I suspect some are failing and not completing in time. You should also separate the timer and a sending thread and only send new data when there is not a previous one running. You basically have everything running with no checks in a timer, very likely to be a bad practice.
Memory gets ‘full’ when you are holding references to too many allocations, or allocations that are too large. In your case, it may be that there are too many objects in memory that are still connected to a ‘live’ variable in your program. If you say:
then 1024 bytes will be locked in memory until the variable 'foo' goes out of scope, at which point the garbage collector can reclaim it. In NETMF libraries, there are lots of hidden allocations. For instance, when doing HTTP or AMQP calls (even async ones), those libraries make (relatively large) allocations that will stay locked in memory until the network operation completes. Doing too many network operations back-to-back (as Brett describes) means that you are filling up memory with allocations that cannot be released until the operations complete. You are filling memory faster than it can be reclaimed by the garbage collector.
If you make requests more slowly, they have time to complete and the underlying allocations can then be reclaimed by the garbage collector.
If, instead, you are just making too many large allocations, then there may be no easy solution - you are working in a constrained environment. But the first thing to do is as Brett suggested - make sure there is only one request in flight at any given time.
I did that before but error was there. So decided to check each component and thn found that http and amqp has memory leaking somewhere so tried to minimize my code as much as possible.
it’s because of your code… Sorry, that’s blunt, but that’s how it is.
Please follow Andre’s suggestion and start figuring out how memory is being retained. Something in your code is being kept and not permitted to clean up. When you understand what that is, you’ll keep memory constant. Refresh your familiarity with the detail about GC in @ mcalsyn’s post too, that’ll help you understand the behaviour
sure. But first, how about you show us some debug stats, analysis in what is going on, and what mods you’ve made to the code you posted the other day taking the feedback we have already given you is ?
using System;
//using System.Collections;
//using System.Threading;
using Microsoft.SPOT;
//using Microsoft.SPOT.Presentation;
//using Microsoft.SPOT.Presentation.Controls;
//using Microsoft.SPOT.Presentation.Media;
//using Microsoft.SPOT.Presentation.Shapes;
//using Microsoft.SPOT.Touch;
//using Gadgeteer.Networking;
using GT = Gadgeteer;
//using GTM = Gadgeteer.Modules;
//using Gadgeteer.Modules.GHIElectronics;
using System.Net;
using System.Text;
using System.IO;
using Microsoft.SPOT.Net.NetworkInformation;
namespace Https
{
public partial class Program
{
GT.Timer timer; // Timer
HttpWebRequest req;
void ProgramStarted()
{
Mainboard.SetDebugLED(true); // LED to Glow indicating Program start
//wifisetup();
NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
ethernetsetup();
timer = new GT.Timer(60000);
timer.Tick += timer_Tick;
}
OK, so another pointer for you. Code Tags. Best used when you have the code in the paste buffer, you hit the code tag, you then paste the code in.
I notice you haven’t protected the send process at all, just got a long running timer. You really need to do that - set a flag, clear the flag as you exit. If you get into the send routine and the flag is already set, don’t try to send again, just log the fact and bail.
You have some diagnostics (debug.print) in your code. What is the output you see ? And did you do any memory profiling and see how it changes over time ? Helping us by debugging this yourself will be necessary, as you’re unlikely to find someone who will just take your code, build a web service like yours, and then test it for you.